Skip to content
Toolsbeginner

What is npm?

Updated Nov 30, 20263 min readBased on official documentation
What is npm?

In short

npm is a package manager and online registry for JavaScript code. Developers use it to download ready-made libraries and tools, share their own packages, and manage the versions of code their projects depend on. It has a website, a command line tool, and a public registry.

npm is the tool most JavaScript developers reach for first when they need code written by someone else. It helps you find, download, update and share small pieces of software called packages. Once you understand the three parts of npm, the rest of its behavior makes much more sense.

The three parts of npm

npm is made of three components that work together:

  • The website, at npmjs.com, where you can search for packages, set up your profile and manage organizations.
  • The command line interface (CLI), a program you run from a terminal. This is how most developers actually use npm day to day.
  • The registry, a large public database that stores JavaScript packages and information about them, such as version numbers and descriptions.

The documentation describes the registry as the world's largest software registry. Developers from many countries publish and borrow packages through it. Many companies also use npm to manage private code that only their own team can see.

How it works

A package is a folder of code with a description file that says what it is called, which version it is and what other packages it needs. These needed packages are called dependencies. When you ask the CLI to install a package, npm looks up its name in the registry, downloads it and any dependencies it requires, and places them in your project.

This saves a lot of effort. Instead of writing a date parser or a file-upload helper yourself, you install a package that already does the job. You can also update packages later, and npm helps you keep track of which versions your project uses. If an underlying library changes, updating the dependency is usually a single command.

npm also lets you run a package without installing it first. The npx tool, which ships with npm, can fetch a package, run it once and then discard it. This is handy for one-off tools.

When to use it

Use npm when you build anything with JavaScript, whether it is a website, a server or a command line tool. It is also the normal way to share your own code. You can publish a package that other people can install with one command. Public packages cost nothing to share. If you need to keep code private, npm offers paid accounts and organizations, which let you invite colleagues and control who can see or change each package.

Some teams prefer a private registry instead. The documentation mentions GitHub Packages and the open source Verdaccio project as options. A private registry lets you publish internal packages without sending them to the public registry.

A simple example

Suppose you have a small project folder and want to use a date library. You could run the following from a terminal inside that folder:

npm install date-fns

npm downloads the package into a folder called node_modules and records it in a file called package.json. Later, anyone who clones your project can run npm install and get the same packages again. Your code can then import the library and use it like any other module.

You can learn more about how tools like this fit into a larger build setup in our guide to webpack or to the fast development server Vite.

Common mistakes

Beginners often commit the node_modules folder to version control. This folder can be very large and is easy to rebuild, so most projects leave it out and rely on package.json instead. Another frequent mistake is installing packages without checking whether they are maintained. Look at when a package was last updated and how many people use it before you depend on it.

Also remember that npm is not the only option in its field. Developers working in other languages use different tools, such as Composer for PHP or Maven for Java. The idea is the same: a registry of packages and a tool that installs them.

Where to learn more

The official CLI documentation includes command line help, its own documentation section and man pages. Use these whenever you want to check what a command does. For beginner tutorials and friendly in-person learning, the documentation points to nodeschool, which hosts free events and self-help material for people learning JavaScript.

FAQ

Is npm free to use?

Yes. You can install packages from the public registry at no cost, and you can share public packages for free too. Private packages and some organization features require a paid account.

What is the difference between npm the website and npm the CLI?

The website lets you search, manage your profile and set up organizations. The CLI is a program you run in a terminal to install, update and publish packages, and it is what most developers use daily.

What does npx do?

npx runs a package without installing it into your project first. It is useful for trying a tool once or running a command that you do not need to keep around.

Can I use npm without sharing my code publicly?

Yes. You can use a private registry such as GitHub Packages or Verdaccio, or pay for private packages and organizations on npm, so your code stays within your team.

Sources

This page is based on the official documentation below. Read it for full detail.

npm — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.