What is npm?
npm (Node Package Manager) is JavaScript’s package manager. It installs libraries, manages dependencies, and runs project scripts. It came bundled with Node.js when you installed it. If you’ve usedpip in Python, npm is the same idea:
| Python | JavaScript |
|---|---|
pip install requests | npm install axios |
requirements.txt | package.json |
pip freeze | npm list |
venv/ | node_modules/ |
package.json
Every JavaScript project has apackage.json file. It describes your project and lists its dependencies — like a requirements.txt with extra features.
package.json
- name and version — project identity
- scripts — commands you can run with
npm run <name> - dependencies — packages your app needs to run
- devDependencies — packages you only need during development (linters, formatters, test tools)
Installing packages
npm install, two things happen:
- The package code downloads into a
node_modules/folder - The package name and version are added to
package.json
Running scripts
Thescripts section in package.json lets you define shortcut commands:
package-lock.json
When you install packages, npm also creates apackage-lock.json file. This locks the exact versions of every package and sub-dependency so that everyone on your team gets identical installs.
- Do commit
package-lock.jsonto git - Don’t edit it manually — npm manages it for you
package-lock.json is like a more detailed version of pip freeze > requirements.txt. It ensures reproducible installs across different machines.What’s next?
You know how npm works. Let’s put it all together and set up a proper JavaScript project from scratch.Project setup
Initialize a JavaScript project and configure the basics