Understanding package.json File
Advertisement
Ad
What is package.json?
package.json is the heart of every Node project. It records metadata, dependencies, scripts, and configuration — telling npm everything about your project.
A Complete Example
{
"name": "my-app",
"version": "1.0.0",
"description": "A demo app",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"test": "jest"
},
"dependencies": {
"express": "^4.18.0"
},
"devDependencies": {
"jest": "^29.0.0"
}
}
Key Fields
| Field | Purpose |
|---|---|
| name / version | Identity |
| scripts | Run commands |
| dependencies | Production packages |
| devDependencies | Dev-only tools |
| main | Entry point |
Version Symbols
"express": "4.18.0" // exact
"express": "^4.18.0" // minor + patch updates
"express": "~4.18.0" // patch updates only
FAQs
What does ^ mean?
Allow updates that don't change the leftmost non-zero number (minor/patch). More in our NPM guides.
Should I edit it by hand?
You can, but use npm install to add dependencies safely.
