The problem npm solves
Imagine you're building a website and you need a calendar widget, a way to bundle your code, and a tool to check for mistakes. You could write all of that yourself from scratch — months of work — or you could reuse code that thousands of experts have already written, tested and shared for free.
npm is how you grab and manage that shared code. It's the tool that downloads ready-made building blocks (called packages) into your project, keeps track of exactly which ones you used, and makes it easy to update them later. Instead of reinventing the wheel, you assemble your project from proven parts.
Quick analogy: npm is like an app store for code. You browse a huge catalogue, "install" the pieces you want with one command, and npm handles getting the right versions and everything they depend on.
npm vs Node.js — what's the difference?
These two always come up together, so let's untangle them:
- Node.js is the program that runs JavaScript on your computer (outside a web browser). It's the engine.
- npm is the package manager that comes bundled inside Node. When you install Node, you automatically get npm too.
So you never install npm separately — installing Node.js gives you both the node
command and the npm command. We'll do that in the next chapter.
The three things people call "npm"
The single word "npm" actually refers to three connected things:
- The command-line tool — the
npmcommand you type in a terminal to install packages and run scripts. This is what you use day to day. - The registry — a giant online warehouse (at npmjs.com) holding over two million free, public packages. When you install something, npm downloads it from here.
- The website — npmjs.com, where you can search for packages, read their docs, and see how popular and well-maintained they are.
What a "package" actually is
A package is just a folder of reusable code that someone published to the registry, along with a small description file. Some packages are tiny (a single helper function); others are whole frameworks. This website, for example, is built from packages like:
- Astro — the framework that turns our files into a fast static website.
- Tailwind CSS — the styling system behind every button and layout here.
- Three.js — the 3D library that powers the engine visualisation.
None of that code was written here from scratch — npm fetched it, and we just used it. That's the whole idea.
Why bother learning it?
npm is the standard way JavaScript and web projects are assembled. The moment you follow any
modern tutorial, clone a project from GitHub, or start with a framework, you'll meet a
package.json file and a npm install command. The good news: you only
need a handful of commands for almost everything, and the next chapters walk you through each
one — what it does and the logic behind it.
Up next: install Node.js (which includes npm), check it worked, and set up the VS Code terminal so you're ready to run your first command.