npm (Node Package Manager) is the default package manager for JavaScript and Node.js, maintained by npm Inc., which is now part of GitHub/Microsoft. It's the #2 most-used dev tool in the world, reported in roughly 56.8% of developer surveys, and it's bundled automatically with every Node.js install. Developers use it because it's the standard way to install, version, and share code from npm's registry โ the largest package registry on Earth, with millions of published packages.
Every npm project has a package.json file that declares its dependencies and scripts. Installing a package updates it automatically.
// package.json
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.19.2"
}
}
# create a new package.json interactively
npm init -y
# install a package and save it as a dependency
npm install express
# run the "start" script defined above
npm run start
npm ships automatically with Node.js โ install Node and npm comes along for free.
# after installing Node.js from nodejs.org, verify both
node --version
npm --version
# install a package globally (CLI tools)
npm install -g typescript