Back to results for “Fundamentals”
Node.js › Node.js Fundamentals & Runtime Architecture

What is npm, and what is its relationship to the Node.js runtime itself?

Beginner

Answer

npm (Node Package Manager) is the default package manager bundled with Node.js installations, providing a command-line tool for installing, publishing, and managing third-party JavaScript packages, along with npmjs.com, the world's largest public package registry hosting those packages -- while npm ships alongside Node.js by default, it's technically a separate project with its own independent versioning and release cycle, and alternative package managers (Yarn, pnpm) can be used in its place for the same fundamental purpose of managing a project's dependencies.
npm init -y              # creates a new package.json
npm install express      # installs a package and adds it as a dependency
npm install --save-dev jest  # installs as a dev-only dependency
npm run test              # runs a script defined in package.json
Real-world example A new Node.js project starts with 'npm init' to create a package.json file, then uses 'npm install' to add Express as a runtime dependency and Jest as a development-only dependency, establishing the project's exact dependency tree, which npm records precisely in a package-lock.json file for reproducible installs.

Common follow-ups: What's the difference between 'dependencies' and 'devDependencies' in package.json, and why does that distinction matter for production deployments?;How does package-lock.json ensure that every developer and deployment environment installs the exact same dependency versions?