Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to NPM
Understanding package.json File

Understanding package.json File

NPM2,538 viewsBy Admin
npmunderstandingpackagejsonfile

Advertisement

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

FieldPurpose
name / versionIdentity
scriptsRun commands
dependenciesProduction packages
devDependenciesDev-only tools
mainEntry 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.

Advertisement