DevAcademy
LearnNode.jspackage.json
BeginnerNode.js

package.json

The manifest file at the heart of every Node.js project.

Reading Time

10 min

Lesson

Lesson 5 of 34

What package.json Describes

package.json is a JSON manifest describing a project — its name, version, dependencies, and the scripts you can run against it. Every Node.js project (whether a library or an app) has one.

A Typical package.json

{
  "name": "my-api",
  "version": "1.0.0",
  "main": "src/server.js",
  "scripts": {
    "start": "node src/server.js",
    "dev": "node --watch src/server.js",
    "test": "vitest run"
  },
  "dependencies": {
    "express": "^4.19.2"
  },
  "devDependencies": {
    "vitest": "^2.0.0"
  }
}

Key Fields

FieldPurpose
name / versionIdentifies the package, especially if published
mainThe entry file when this package is imported
scriptsNamed commands runnable with npm run <name>
dependencies / devDependenciesPackages the project needs
enginesThe Node.js version(s) the project supports

Running a Script

npm run dev
# "start" and "test" have shorthand: npm start, npm test

Semver in Dependency Versions

"^4.19.2" means "4.19.2 or any later compatible version within the same major version (4.x.x)". A caret (^) allows minor and patch updates; a tilde (~) allows only patch updates; an exact version pins it precisely.

Best Practice

Give every script a clear, conventional name (dev, build, start, test, lint) — it makes a project instantly navigable to anyone familiar with the Node.js ecosystem, without reading any documentation.

Interview Questions

Quick Quiz

1. What does the scripts field in package.json define?

2. What does the caret (^) mean in a version like "^4.19.2"?

3. What shorthand exists for npm run start?