Using pnpm as the package manager in nodejs projects

By Bala | Bala | 20 Apr 2023


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.

image.png

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 @balaz as a Hive Witness

 

Vote @kanibot as a Hive Engine Witness

 


qjrE4yyfw5pJD9LKQ1BG3NbSyKTowh8wnMyt99dK1UPEkAAsgygincveTbT6c9mQn2FjHQKTrSCy4VodV2BeGrrUYhYALXcPP7zMVVgpzvwiX1ZGczXYyQXp.webp?format=webp&mode=fit 8SzwQc8j2KJa5zNbRVVrXnjUH7HeFHWfeS6aA81JxfFe6qdWqg5LTFpmft9g9sJnTThvVGirtRvu3qSwkxJvgPc7wEE69pJp5rZ2ZXnZnPkqJDYcHEE.webp?format=webp&mode=fit FUkUE5bzkAZT3HzV5tJDiU2ik81PCd4JCyhWnRcDN8XJsVFY3UNB8DCRUuhCDN66wiMnTycF4W5TM6SbQHGDwYmP1FStMmkUvfPEVxYfXyDTCmU2bEwm3fiku8ti6aos9RroLdtDQHPhjEDFeNyzYWy7k1g6WcZGHHGJ.webp?format=webp&mode=fit 3W72119s5BjW4PvRk9nXC1RsHWxNoWjhqsdMpcQrTsuSz5KpfZW7qpxhpoSQZvFhxkRRmq1UF41U8uxdrJDzJnoJ8ZxCS5GvqdJLbrGYbMeySF4iXYaEXp.webp?format=webp&mode=fit 2gsjgna1uruvGBHDnRaj2zVCcpeJW4jyLMe4SBCGvYRn4kXTQGFWvCLdiA9W4zv1tZV6Yvh46bKBawf8GCSfXvVWPUrg2zxTdRztPy74sCAg9ZZK3k.webp?format=webp&mode=fit 3W72119s5BjW4PvRk9nXC1RsHWxNoWjhqsdMpcQqzxxkgPuJFq7EcFz1sUUCcJwEk8zQ2zYKBtbXBrdJEjCpw1YuaREa8cBFZpYhib711zbJgapbJQZrwx.webp?format=webp&mode=fit

How do you rate this article?

4


Bala
Bala

Developer | Writer | Blogger | Gamer | Blockchain Enthusiast


Bala
Bala

This is my general blog. I share different articles I write every single day.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.