Using pnpm as the package manager in nodejs projects

0 37
Avatar for bala41288
1 year ago

I have been slowly switching to pnpm as my default package manager. The main reason is that it is fast and consumes only less space. It manages the node_modules folder very well I think. I have also been working on converting my nodejs projects to a type module that uses import statements instead of require. Along with that, I have also started using pnpm as my default package manager.

I have been using pnpm for almost all my new projects and even for existing projects, I have switched from npm to pnpm. There is also yarn but I did not see any advantages in using yarn and had been using npm now pnpm has more advantages and that's why I have switched to this. I would like to list some of the advantages of this article.

Source

Less disk space

This is one of the biggest advantages. Usually, after we do npm install, the size of the node_modules folder would go very high. Especially if the project is a heavy one with lots of libraries, there is a high chance that the node modules folder would occupy a lot of space.

pnpm uses a mechanism where duplication of packages is avoided. If multiple projects have different dependencies, npm usually has a copy of each of the dependent projects. But pnpm maintains a global store and caches of the packages to reduce disk space usage. This has been a great advantage for bigger projects.

Installation is faster

With the caching mechanism, the installation time is also faster. Compared to the other package managers, pnpm uses a shared folder for all the packages which makes the installation time very small. This shared folder mechanism is also one of the reasons for reduced disk space. This gives a better experience to the users than the other package managers. Especially better than the default npm package manager.

Easy to use

I wouldn't argue that npm is very hard to use. But I would like to say that pnpm is also very easy to use similar to other package managers. Any beginner would even find this easy to use. I have heard that there are some integrations available. I have not experimented with it personally.

Reduced need for network bandwidth

Some people might be in a limited data plan and the npm install when it happens, downloads a huge amount of data from the registry every time it happens. But as pnpm uses a shared store, the amount of times a package is downloaded is very less comparatively. Even for someone who is having limited data and a low-speed connection, this can be very handy and useful because the download time will also be reasonable.

Compatible with other package formats

It is very common that there would be projects using other package managers and we might have to still deal with other package formats. This can include Bower, Yarn, or even npm. It is very comfortable that pnpm can be used to manage projects that are using different package managers.


If you like what I'm doing on Hive, you can vote me as a witness with the links below.

Vote@balazas aHive Witness
Vote@kanibotas aHive Engine Witness



1
$ 0.00
Avatar for bala41288
1 year ago

Comments