npm & package.json

๐ŸŸข Node.js LTS ๐Ÿ“— Chapter 8 of 49 ๐Ÿ“‚ Phase 3: Modules & npm ๐Ÿ—“๏ธ 2026 Edition
๐Ÿ“Œ Covered in this chapter: npm init ยท npm install ยท Dependencies vs devDependencies ยท Semantic Versioning ยท npm scripts ยท npx

Master npm โ€” Node's package manager โ€” including installing dependencies, semantic versioning, npm scripts, and npx.

1npm & package.json โ€” What You'll Learn

Master npm โ€” Node's package manager โ€” including installing dependencies, semantic versioning, npm scripts, and npx.

Here's everything this chapter covers, in the order you'll learn it:

  • What npm is
  • Creating package.json with npm init
  • Installing packages
  • Uninstalling packages
  • Development dependencies vs production dependencies
  • Package versioning
  • Semantic versioning (major.minor.patch)
  • package-lock.json's role
  • npm scripts for common tasks
  • npx to run packages without installing globally
  • Updating and auditing packages
  • Publishing packages (overview)
2Working Example
๐Ÿ’ป Example: npm & package.json
npm init -y
npm install express
npm install --save-dev nodemon
npm run dev
๐Ÿ’ป Continued Example
{
  "scripts": {
    "start": "node src/server.js",
    "dev": "node --watch src/server.js"
  }
}
3Best Practices & Common Pitfalls
๐Ÿ’ก Key things to remember:
  • Dependencies (--save, default) are needed to run your app in production; devDependencies (--save-dev) are only needed while developing (like testing tools).
  • Semantic versioning: MAJOR.MINOR.PATCH โ€” a bump in MAJOR usually means breaking changes.
โ“ Frequently Asked Questions (FAQ)

Q What's the most important thing to understand about npm & package.json?

Focus on: npm init ยท npm install ยท Dependencies vs devDependencies ยท Semantic Versioning ยท npm scripts ยท npx. These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.

Q Do I need external npm packages for npm & package.json?

Only where explicitly shown in the code examples above (like Express, Zod, or Socket.IO) โ€” otherwise, this chapter relies entirely on Node.js's own built-in capabilities.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Node.js LTS ยท Last updated August 2026