Skip to main content

package.json — Node.js Project Manifest

Learning Focus

package.json is the cornerstone JSON config in the JavaScript ecosystem. Every Node.js project starts with it.

Anatomy of package.json

package.json
{
"name": "my-app",
"version": "1.0.0",
"description": "A Node.js web application",
"main": "dist/index.js",
"type": "module",
"scripts": {
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts",
"build": "tsc",
"test": "jest --coverage",
"lint": "eslint . --ext .ts",
"format": "prettier --write ."
},
"dependencies": {
"express": "^4.18.2",
"zod": "^3.22.0"
},
"devDependencies": {
"typescript": "^5.3.0",
"jest": "^29.7.0",
"@types/express": "^4.17.21"
},
"engines": { "node": ">=18.0.0" },
"license": "MIT"
}

Version Specifiers

SpecifierMeaning
"4.18.2"Exact version only
"^4.18.2"Compatible with 4.x.x
"~4.18.2"Patch updates only: 4.18.x
">=4.0.0 <5.0.0"Range expression

dependencies vs devDependencies

CategoryInstalled WhenExamples
dependenciesAlwaysexpress, zod
devDependenciesDev onlytypescript, jest, eslint
peerDependenciesProvided by host appReact component libraries

Common Pitfalls

PitfallConsequencePrevention
Committing node_modulesHuge repo, wrong binariesAdd to .gitignore
"*" version specifierBreaking changes break appUse ^ or exact pin
Tool deps in dependenciesInflated production bundleMove to devDependencies
Missing enginesRuns on wrong Node versionSpecify "node": ">=18"

What's Next