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
| Field | Purpose |
|---|---|
| name / version | Identifies the package, especially if published |
| main | The entry file when this package is imported |
| scripts | Named commands runnable with npm run <name> |
| dependencies / devDependencies | Packages the project needs |
| engines | The Node.js version(s) the project supports |
Running a Script
npm run dev
# "start" and "test" have shorthand: npm start, npm testSemver 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.