What npm Does
npm (Node Package Manager) installs third-party packages from the npm registry, manages their versions, and runs project scripts — it is the backbone of the Node.js ecosystem.
Common npm Commands
npm init -y # create a package.json
npm install express # install a dependency
npm install -D typescript # install a dev-only dependency
npm uninstall express # remove a dependency
npm run <script> # run a script defined in package.jsonDependency Types
| Type | Flag | Example |
|---|---|---|
| dependencies | (default) | express, react — needed to run the app |
| devDependencies | -D or --save-dev | typescript, eslint — only needed during development |
| peerDependencies | n/a — declared in package.json | A version a plugin expects the host app to already provide |
Installing Everything from package.json
npm install
# Reads package.json and installs every listed dependency into node_modulespackage-lock.json
npm generates a package-lock.json file recording the exact resolved version of every package (including nested dependencies). Committing this file ensures everyone on a team — and your CI pipeline — installs the exact same versions.
Best Practice
Always commit package-lock.json to version control. It is what makes "works on my machine" dependency issues far less common.