What is NPM and How Does it Work?
Advertisement
Ad
What is NPM?
NPM (Node Package Manager) is the default package manager for Node.js and the world's largest software registry, with over 2 million packages. It installs and manages your project's dependencies.
Basic Usage
npm init -y # create package.json
npm install express # add a dependency
npm install -D jest # add a dev dependency
npm uninstall express # remove
npm update # update packages
package.json — Your Project Manifest
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"start": "node index.js",
"test": "jest"
},
"dependencies": {
"express": "^4.18.0"
}
}
Running Scripts
npm start
npm test
npm run build # custom scripts need "run"
FAQs
dependencies vs devDependencies?
Dependencies run in production; devDependencies (test tools, bundlers) are only for development. More in our NPM guides.
What is package-lock.json?
It locks exact versions for reproducible installs — always commit it.
