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 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 from a library if you have used it before; it simply creates a link to the local repository.
The other great advantage is the lower disk space usage. PNPM only keeps one copy of each package instead of storing multiple copies in different projects. This means a good saving of space, especially if you have many projects that use common dependencies.
It is 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 will see how to install PNPM. If you need more information, you have the detailed instructions on the official PNPM site.
Installation via 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 run.
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 we want to install PNPM without having Node.js installed, we can do so using the Standalone installer.
If you’re 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 installation process of PNPM on your system. Once completed, you should see a message indicating that the installation was successful.
Verifying the Installation
To ensure that the installation was successful, you can check the version of PNPM that you have installed. Open a command console and type,
pnpm --version
You should see the installed version of PNPM. 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:
pnpm install
: Installs the project’s dependencies.pnpm add <package>
: Adds a new package to the project.pnpm remove <package>
: Removes a package from the project.pnpm run <script>
: Runs a script defined in thepackage.json
file.
Basically, you can do everything we have seen in the course for NPM, but with PNPM. The syntax is compatible