que-es-pnpm

What is and how to use PNPM

  • 3 min

PNPM is a package manager for Node.js projects that offers significant advantages in terms of storage and speed compared to other tools (like NPM or Yarn).

Unlike other package managers like NPM and Yarn, which download and install each package in a separate node_modules directory for each project, PNPM uses a centralized storage and links installed packages via hard links.

The main advantage of the centralized system is to greatly improve the speed of installing and uninstalling dependencies. PNPM doesn’t have to download a library again if you’ve used it before, it simply creates a link to the local repository.

The other major advantage is the lower hard disk space usage. PNPM only saves one copy of each package instead of storing multiple copies in different projects. This means good space savings, especially if you have many projects that use common dependencies.

It’s a very good alternative to NPM, and the syntax and usage are basically identical. But, with a very important improvement in speed and efficiency.

Installing PNPM

Next, we are going to see how to install PNPM. If you need more information, you have the detailed instructions on the official PNPM site.

The easiest option, if we have Node.js on your computer, is to add it as a global package via NPM. To do this we run.

npm install -g PNPM

This will install PNPM globally on your computer (meaning you can use it in any Node.js project).

If we want to install PNPM without having Node.js installed, we can do it via the Stand Alone installer.

If you are on Windows, open a PowerShell console. Here, copy and paste the following command line and press Enter,

iwr https://get.pnpm.io/install.ps1 -useb | iex

This will start the PNPM installation process on your system. Once completed, you should see a message indicating that the installation was successful.

Verifying the Installation

To make sure the installation was done correctly, you can verify the version of PNPM we have installed. Open a command console and type,

pnpm —version

You should see the installed PNPM version. For example, something like this.

8.15.3

Using PNPM

Once PNPM is installed on your system you can use it to manage the packages of your Node.js project in the same way you would with NPM or Yarn.

Some common commands include:

CommandDescription
pnpm installInstalls the project dependencies.
pnpm add <package>Adds a new package to the project.
pnpm remove <package>Removes a package from the project.
pnpm run <script>Executes a script defined in the package.json file.

Basically, you can do everything we’ve seen in the course for NPM, but with PNPM. The syntax is compatible.