npm

a plain-language explainer

npm is the tool that fetches and manages the ready-made building blocks your project borrows from others. Almost every modern web project leans on pieces other people have written and shared; npm goes and gathers exactly the ones your project needs, in the right versions, with a single command.

Nobody builds a modern website entirely from scratch, any more than a cook grinds their own flour and presses their own oil. There’s a vast, generous shared pantry of building blocks — small pieces of software other people have written and given away — and almost every project borrows from it. npm is the helper that goes to that pantry and fetches exactly the ingredients your project calls for.

You’ll meet npm the moment you work on most web projects. It’s so routine that, once you know what it’s doing, the mystery falls right away.

What it’s actually for

A project usually comes with a little shopping list — a plain file that says “this project needs these particular pieces, in these versions.” You don’t write each piece yourself; you just ask npm to read the list and go gather everything on it. One command:

npm install

That’s the one you’ll run most. It reads the project’s shopping list and fetches every building block named on it, tucking them into a folder so your project can use them. The first time you open most projects, this is the very first thing you do — it’s how a folder of code becomes a thing that can actually run.

Where do these pieces go, and what’s that “node_modules” folder?

When npm fetches everything, it puts it all into a folder called node_modules. It can look alarming — sometimes thousands of files appear! — but there’s nothing to fear: it’s just the pantry, stocked. Those are all the borrowed building blocks (and the blocks they in turn rely on), gathered in one place for your project to draw on.

You never edit that folder by hand, and you don’t keep it forever — if it’s ever lost or deleted, a single npm install rebuilds it from the shopping list. That’s why people don’t even bother backing it up: the list is the truth; the folder is just the list, fetched.

The other command you’ll meet

Projects also keep a small set of named shortcuts for common tasks — “build the site,” “start it up for testing” — and you run those through npm too:

npm run build

Whatever a project names its tasks, npm run something is how you trigger them. (You may have seen npm run deploy in the Cloudflare story — same idea: a named shortcut the project defined, run through npm.) You don’t have to memorize them; a project’s notes will tell you which ones it offers.

”node,” “yarn,” “pnpm” — are those the same thing?

You’ll see these neighbors and it’s worth a quick, calming word on each:

  • Node (or Node.js) is the engine that runs this kind of code outside a web browser; npm comes along with it, which is why installing one gives you the other.
  • yarn and pnpm are simply alternative tools that do npm’s job — fetching the building blocks — sometimes faster or more tidily. If a project uses one of them, the spirit is identical; only the command’s name changes (yarn install, pnpm install).

So they’re not new worlds to learn — just different doors into the same pantry.

So, in one breath

npm is the helper that reads your project’s shopping list of borrowed building blocks and fetches them all with npm install, and that runs a project’s named tasks with npm run — the routine first step that turns a folder of code into something that actually runs, drawing on the vast shared pantry that modern web work is happily built upon.