Language: EN

que-es-pnpm

What is and how to use PNPM

PNPM is a package management tool for Node.js projects that offers significant advantages in terms of storage and speed compared to other tools such as 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 the installed packages through hard links.

The main advantage of the centralized system is to greatly improve the speed of installing and uninstalling dependencies. PNPM does not have to download packages again if you have used a library previously, it simply creates a link to the local repository.

The other great advantage is the reduced disk space usage. PNPM only saves one copy of each package instead of storing multiple copies in different projects. This means a significant space saving, especially if you have many projects using common dependencies.

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

Installing PNPM

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

Installation through NodeJS

The simplest option, if you have Node.js on your computer, is to add it as a global package using NPM. To do this, we execute.

npm install -g PNPM

This will install PNPM globally on your computer, which means you can use it in any Node.js project.

Standalone Installation (without NodeJS)

If you want to install PNPM without having NodeJs installed, you can do so using the Stand Alone installer.

If you are on Windows, open a PowerShell console. Here, copy and paste the following command 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.

Installation Verification

To ensure that the installation was successful, you can check the version of PNPM that is installed. Open a command prompt 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 in your Node.js project in the same way you would with NPM or Yarn.

Some common commands include:

  • pnpm install: Installs 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.

But basically, you can do everything we have seen in the NPM course, but with PNPM. The syntax is compatible.