NPM: the NodeJS Package Manager
In the previous article, we learned how to use NodeJS to run JavaScript on your computer. While this is useful already, NodeJS programs become even more powerful when you add another tool: NPM, or Node Package Manager.
NPM is a tool that builds upon NodeJS’s powers to help us reuse other people’s code in our projects, as well as share our own with the world. Luckily, NPM comes bundled with NodeJS, so once you’ve installed NodeJS, you can start using NPM as well.
In this article, we’ll go into more detail about what NPM is and how it can be useful for you. By the end, you’ll understand:
- How NPM can help you reuse existing code in your own programs
- How to explore the many code packages in the NPM package registry
- Package managers, and why they’re useful
Learning about the broad concepts will increase your confidence—but if you’d like to see things in action first, you can skip ahead to “Learn—and practice!—NPM”. Once you’ve seen the how, you can come back later for all the what’s and why’s.
For many of us, coding is a communal effort, where people share code that makes everyone’s lives easier, and proactively provide solutions to problems others might have. For the sake of convenience (and the joy of sharing), developers often bundle their code in “code packages”—installable units of pre-built functionality that can then be reused by themselves or others.
To make them easier to distribute and discover, these code packages are uploaded to package registries. These package registries are browsable indexes of—sometimes millions!—code packages for people to exchange, “check out”, and build upon. These packages span the whole spectrum of what code can be: from small utilities to wholesale programs.
Unfortunately, sifting through so many packages to choose from, and managing those installed can quickly get overwhelming. Fortunately, that’s where another helpful tool comes in: package managers that automatically download, install, and organize code packages for us.
NPM: Nodejs’s (Code) Package Registry and Manager
Section titled “NPM: Nodejs’s (Code) Package Registry and Manager”NPM is the standard package registry and manager for NodeJS. If we think of code packages as magic books of reusable incantations, then NPM is a library and the librarian for those books. As a library, the NPM registry is a catalog of code packages written and distributed by all sorts of developers for public use. And as a librarian, the NPM manager knows exactly how to fetch the packages we want and keep them updated, so we can focus on the fun part—the magic.
You might be wondering: how can NPM be both a library and a librarian? The secret is that NPM actually consists of two separate but connected parts:
- The NPM website is NodeJS’s package registry. It’s an online catalog of reusable code, where you can search through countless available packages, read their documentation, and even see their code in-browser.
- The NPM command line, which comes included with Node, is NodeJS’s package manager. It wrangles and delivers code packages from the package registry. Like asking a librarian for help finding a book, all you have to do is enter a command to download a package from the registry, and NPM will do the rest by installing it in your project.
What we can create with JavaScript—and NodeJS—is an endless world of possibilities. Similarly, code packages you can find in the NPM registry range from things like scripts that add special webpage effects, a CSS library for your UI, static website builders like Astro, and a whole lot more. If you ever find yourself wishing for a feature you don’t really know how to (or want to) make, search the NPM registry, because there’s a good chance it might already exist.
By using NPM, you’ll also have access to countless tools that can simplify and power-up your web development journey, whether it’s customizing your text editor or creating an entire website from scratch. No matter how much coding experience you have, introducing NPM into your workflow will speed up your learning process so you don’t get stuck on the little things.
As the largest and most popular collection of JavaScript code packages (and more! ), the NPM package registry gives you access to a wide ecosystem of programs and reusable code already written by other developers. Through the registry, you can find many different tools for your projects, codespace, and whatever else you might need in your workflow.
For example, some of my favorites are:
- Prettier, a formatter that cleans my code and makes it more readable;
- Sharp, a tool that compresses images and turns them into web-friendly reasonably-sized files;
- Chance, a random generator that can be used on both the command line and my websites.

Additionally, accessing a package registry allows you to review information about a program, in addition to downloading its files. So before installing a package, be sure to check out its:
- Documentation, sometimes also the README, which contains everything the developer wants you to know about the program: its purpose, intended use cases, how the code works, installation, additional options, and known issues. You should always review documentation before downloading anything, so you know what to expect.
- Reputation, since you’ll most often download code written and distributed by strangers. Anything you download from the internet has the potential to be unsafe, and while a good reputation doesn’t necessarily guarantee safety, popular packages from reputable sources are less likely to be malicious.
- Source and recent updates, so you can see where the code is coming from and if the developer is still working on it. You might determine a package’s source is safe if you trust the distributor or developer; if you reviewed the “Code” tab for anything suspicious; or if the package has an open source GitHub repository where you can see who built it as well as any recent updates. Though there is no perfect system that will promise usability, the more information you have access to, the better your judgment will be.

Now that you have some idea of what’s out there, try exploring the library at npmjs.com! You can also check out their guide and documentation on searching for packages.
(And if you’re really curious, here are the packages released by FujoCoded!)
Your Dependable Librarian: The NPM Package Manager
Section titled “Your Dependable Librarian: The NPM Package Manager”NPM is used as a package manager through the command line in order to download, install, and manage code packages as well as your projects in a variety of ways. With it, you can update installed packages, create personalized shortcuts, and even upload and share your own code, if you ever want to get more advanced.
NPM manages everything with package.json, a file in the root
directory of your NPM project. Any code you’ve downloaded from the NPM
registry is automatically added into your project’s node_modules folder. We’ll
learn more about this in the next article.
Though there are other package managers out there, we strongly recommend that
you stick with NPM until you gain more experience. Once you’re comfortable and
discover more resources, you might hear about other options such as yarn,
pnpm, deno, and bun. While they all have their differences, the concepts
you learn here are broadly applicable to most others.
Package managers exist in the first place to help developers build their projects more efficiently, regardless of a project’s complexity. Though everything a package manager does could be done by us humans, we’ll soon run into problems when new code gets added, packages get updated (a never-ending process), and especially when it comes to untangling dependencies.
Because coding is a communal effort, code packages often reference other code packages to use. This relationship between code packages is called a dependency. Much like how you can use NPM to reuse other people’s code, so do the code packages themselves. By using a package manager, your computer can sort out all the dependencies by looking at pre-existing registries and keeping your code updated. This will save you from many, many, many future headaches if you try to do it all yourself.
As your project grows, a package manager will keep your code up-to-date and maintain the stability of your project. Most code can be run regardless of package manager, so you’re not expected to rely on only one. If a specific package manager is required, the program’s README should tell you which one to use. However, we highly suggest for you to use NPM because of its popularity among developers, and therefore the amount of resources you’ll have access to.
You now have a solid, foundational understanding of what NPM is, why it’s such a critical tool for modern web development, and how it can make you even more powerful—and save you time!—by letting you easily reuse other people’s code.
With the what and the why, in your graspyou’re ready to move on to the how: our next guide, “Learn—and practice!—NPM”, will walk you through the most common commands and show you how:
- Initialize a new NodeJS project with NPM
- Install your very first package from the NPM registry
- See how NPM uses the
package.jsonandnode_modulesto keep your project organized.