package.json (Node.js)

package.json is the manifest file at the root of a Node.js project. It records the project's name, version, dependencies, scripts, and metadata, and it is what npm reads to install packages and run commands.

Node.js

package.json is the heart of a Node project. Its dependencies and devDependencies sections list the packages your code needs (with version ranges), so npm install can recreate node_modules exactly. The scripts section defines shortcut commands you run with npm run, such as start, build, and test.

Other important fields include name and version (required to publish), main or exports (the entry point when the package is imported), type ("module" to switch the project to ES Modules), engines (supported Node versions), and bin (CLI commands the package provides).

You create it with npm init (npm init -y for defaults). Keep it tidy: distinguish runtime dependencies from devDependencies (build tools, test runners), and commit it along with package-lock.json so collaborators and CI install identical versions.

Syntax

{ "name": "app", "scripts": {...}, "dependencies": {...} }

Examples

JavaScript

{
  "name": "my-api",
  "version": "1.0.0",
  "type": "module",
  "scripts": { "start": "node server.js", "test": "jest" },
  "dependencies": { "express": "^4.18.0" }
}

Learn it in a lesson

See also

Back to the Dictionary