Before going further, it helps to understand the problem npm solves.
What a package is
Most JavaScript projects are built from reusable pieces of code — a framework like React or Astro, a tool like TypeScript or ESLint, a small library that solves one focused problem.
In this ecosystem, those reusable pieces are called packages.
A project rarely uses just one. It usually depends on many.
What npm is
npm is the default package manager for Node.js.
In practical terms, that means two things:
- It usually comes with Node.js.
- It gives JavaScript projects a standard way to declare, install, and update packages.
One detail is worth knowing early: people sometimes use the word npm to refer to more than one thing.
Depending on the context, npm may refer to:
- the CLI tool you run in the terminal
- the public package registry at
npmjs.com - the broader package ecosystem around that registry
In this course, npm usually means the package manager CLI unless the registry is mentioned explicitly.
What problem npm solves
Without a package manager, every project would have to manage its dependencies by hand.
That would mean:
- finding packages manually
- downloading them manually
- putting them in the right place manually
- repeating that process for updates
- explaining the exact dependency setup to every other person who works on the project
That approach does not scale well. It is slow, inconsistent, and difficult to reproduce across machines.
npm turns that work into a predictable system.
The four jobs npm does
1. It records what a project depends on
That record usually lives in package.json.
package.json often contains:
- the project name
- the project version
- the dependencies the project needs
- scripts such as
dev,build, ortest
2. It installs packages
If a project needs a package, npm can download it and make it available to the project.
For example:
npm install react
That command installs the react package and records it in the project.
By default, npm installs packages from the public npm registry. That is one reason the phrases “npm package” and “JavaScript package” often overlap in day-to-day conversation.
3. It records the exact dependency graph that was installed
This is the job of package-lock.json.
That file matters because direct dependencies are only part of the story. A package such as react may depend on other packages, and those packages may depend on still more packages.
The lockfile records the exact resolved versions so installs stay reproducible.
4. It runs project scripts
Projects often define scripts in package.json, for example:
{
"scripts": {
"dev": "astro dev",
"build": "astro build"
}
}
Then npm can run them:
npm run dev
npm run build
This gives the project a small shared command surface instead of requiring everyone to memorize underlying tool commands.
What Node.js has to do with this
npm belongs to the broader Node.js ecosystem.
The short version is:
- Node.js runs JavaScript outside the browser.
- Many JavaScript tools are built for Node.js.
npmis the package manager that ships with that ecosystem.
You do not need deep Node.js knowledge before learning npm. You only need to recognize that npm is part of the same environment.
The short version
npmhelps a project describe what it needs, install those things, and run common project tasks.
That is the core idea behind everything that follows.