QA
Beginner LevelNode JS

What is the difference between dependencies, devDependencies, and peerDependencies in package.json?

❓ Interview Prompt: Explain package.json dependency fields, semver versioning ranges (^, ~), dependencies vs devDependencies vs peerDependencies.

'package.json' categorizes project dependencies:

•
'dependencies': Modules required for production runtime (e.g. Express, Mongoose).
•
'devDependencies': Tools needed ONLY during development/build (e.g. TypeScript, ESLint, Jest).
•
'peerDependencies': Directs consuming projects to install a compatible version of a parent library (e.g. React plugins).
•
Semver ('^1.2.3' vs '~1.2.3'): '^' allows minor/patch updates; '~' allows patch updates only.

Code Implementation Example

json
{
  "name": "my-api",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.19.2"
  },
  "devDependencies": {
    "typescript": "^5.4.5"
  }
}
💡package.json dependency declaration structure.
🎯 Interview Key Takeaway

Keep build tools in devDependencies to maintain lean production container deployments.

#package.json#npm#dependencies#semver#Beginner
Back to all Node JS Questions→

More Node JS Interview Questions

Beginner LevelNode JS

How does the Node.js Event Loop work? Explain the 6 execution phases (Timers, Pending, Poll, Check, Close).

Beginner LevelNode JS

What does 'Single-Threaded, Event-Driven, Non-Blocking I/O' mean in Node.js?

Beginner LevelNode JS

What is the difference between process.nextTick() and setImmediate()?