Node package manager или npm был впервые запущен в 2010, а в 2021, он содержит уже больше 500k пакетов (модулей) с открытым кодом, которые ты можешь использовать в своих Node.js приложениях.

По отношению к npm, термины пакет и модуль взаимозаменяемы.

Как найти пакет на npm

Чтобы найти нужный пакет, перейди на официальный сайт npm и напечатай поисковый запрос в строку поиска.


The issue is that as of 2020, this is only useful if you know the name of the package you’re looking for.

If you have a broad query, i.e. how to change the color of output in Node.js I suggest using Google search instead.

How to install an npm package

Once you’ve found what you’re looking for, you can navigate to the description of the package.

It displays the content of the file that the developer has added to the project.

Here’s an example for the module chalk . As you see, it contains installation and usage instructions.

All npm packages can be installed using the CLI tool npm and its install command.

npm install package_name

Navigate to your project directory, substitute the package_name placeholder with the actual name of the package you’re installing.

npm install chalk

This command will install the chalk module and all its dependencies.

How to install all project dependencies

In the root folder of your Node.js project, there’s a file called package.json. Among other things, it describes your project’s dependencies:

  "dependencies": {
    "chalk": "^4.1.0"

The useful thing about the dependencies section is that it might contain tons of modules and you don’t have to run npm install module_name for each of them.

A single npm install in the root of your project will install all the dependencies listed in package.json.

Saving the module dependency with the -s flag

In most cases, there’s no need to edit package.json manually.

You can automatically add the dependency to it by running the installation with the -s flag or --save.

npm install --save chalk

Which is the same as

npm install -s chalk

Global installation with the -g flag

You can install the package globally using the -g flag. For the module like chalk, it doesn’t make much sense, but there are multiple other CLI tools that you might want to use globally in your system.

npm install -g firebase-tools

This will install the module firebase-tools and allow you to run the command firebase anywhere in your terminal.