DEV Community

Cover image for Stop using npm or yarn to install node_modules
Kristiyan Velkov
Kristiyan Velkov

Posted on

Stop using npm or yarn to install node_modules

PNPM saves disk space, boosts installation speed, and creates a non-flat node_modules directory.

What is pnpm ?

Pnpm is a package manager for JavaScript and Node.js applications. It stands for "Fast, disk space efficient package manager" and is designed to address some of the limitations and issues associated with other popular package managers like npm and Yarn.


Why pnpm ?

pnpm has three big goals:

  • saving disk space 
  • boosting installation speed
  • creating a non-flat node_modules directory.

Image description

Image description


Here are several reasons why you might consider using pnpm over Yarn and npm:

  1. Disk Space Efficiency: pnpm's approach of using a shared store and hard linking significantly reduces disk space requirements compared to Yarn and npm. This can be particularly advantageous when working on multiple projects or maintaining a large codebase, as it saves valuable disk space.

  2. Faster Installations and Updates: pnpm is designed to optimize installation and update processes. By leveraging parallel execution of scripts and efficient dependency resolution, pnpm can provide faster installation and update times compared to Yarn and npm, especially for projects with numerous dependencies.

  3. Network Bandwidth Optimization: With pnpm, you can set up a store server to share packages across projects and machines. This helps reduce network bandwidth usage by avoiding redundant downloads. It can be particularly beneficial in team settings or when working on distributed systems.

  4. Improved Development Workflow: pnpm offers features that can enhance your development workflow. For example, it supports parallel execution of scripts, which can speed up tasks like building, testing, and linting. Additionally, pnpm integrates well with other development tools and has an active community contributing to its improvement.

  5. Compatibility and Ecosystem Support: pnpm is compatible with the npm registry and uses the same package.json format, making it seamless to work with existing npm-based projects. It also integrates with popular build tools, testing frameworks, and development workflows. While npm and Yarn have larger ecosystems, pnpm has been gaining popularity and community support.


Image description

linkedin


Image description

If you like my work and want to support me to work hard, please donate via:

Revolut website payment or use the QR code above.

Thanks a bunch for supporting me! It means a LOT 😍

Top comments (17)

Collapse
 
nafg profile image
nafg

This wasn't written by chatgpt was it?

How exactly does it stand for "Fast, disk space efficient package manager"?

Collapse
 
jamesthomson profile image
James Thomson

The real answer:

pnpm stands for performant npm. @rstacruz came up with the name.

Src: pnpm.io/faq#what-does-pnpm-stand-for

Collapse
 
nafg profile image
nafg • Edited

My point is, the whole article reads sort of like ChatGPT, and saying that a word stands for something that doesn't abbreviate to it at all is just the sort of thing ChatGPT does.

The only exception is the table and graph, but it could have been generated separately, and the prompts are omitted.

Thread Thread
 
kristiyan_velkov profile image
Kristiyan Velkov • Edited

Hello, thank you for comment @nafg.

Yes, I use ChatGPT for some of my paragraphs, but hey mate, why do not use it ?

I didn't understand what is most important for you the information or how the article was written ?

Thread Thread
 
nafg profile image
nafg
  1. Then you should give it attribution and not give the impression that you wrote this yourself, of your own knowledge
  2. Perhaps more importantly, chatgpt is completely unreliable. If you are just pasting text that it generated, it could be full of information that's wrong, misleading, or misleading by omission.
  3. We can all access chatgpt ourselves. There's no need to spam a site that's ostensibly human-authored content, where we expect to learn from other people who have what to teach us, with content that we can get ourselves from chatgpt.
Thread Thread
 
kristiyan_velkov profile image
Kristiyan Velkov • Edited

So, I understand and agree with you of some of the points. Thank you!

But is it better like you to spam only and not to contribute at all, but you can judge people by what they use.

Please, write at least one article and you will see that is not so easy , so probably will stop to spam others.
Based on your profile and name mate you look like someone who want only to spam and distract people from what is most important - to learn something new.

Of course you can find almost everything in the web if you want.
People like you also.

Please, don't spam any more. Wish you all of the best.

Thread Thread
 
nafg profile image
nafg

Based on my name and profile how?

I'm pretty active on GitHub, so I guess you didn't check that

Collapse
 
supportic profile image
Supportic • Edited

No docker viable = unusable

It's not possible to share your pnpm global store across containers with a volume to leverage the symlinks. The virtual-store-dir variable in node_module/.modules.yaml has an relative path. This requires to have the same path structure and even then, the symlinks won't work and it loads the source files inside the node_modules directory. Running pnpm in 2 different containers will require to install dependencies again…
pnpm.io/docker

Collapse
 
kristiyan_velkov profile image
Kristiyan Velkov

I understand your concern with using pnpm in Docker containers, and it's true that sharing the global store directly using volumes might not work as expected due to the relative paths in the virtual-store-dir variable.

While using pnpm in Docker containers may not be viable with direct volume sharing, there are alternative approaches to handle dependencies efficiently. One option could be to use Docker multi-stage builds to cache the installed dependencies between build stages. This way, the dependencies don't have to be reinstalled each time you build the image.

Additionally, you could consider creating a custom base image with the frequently used dependencies pre-installed. This way, you can minimize the need to re-install them across multiple containers.

Every tool has its strengths and limitations, and it's essential to find the right balance that fits your specific use case. If using pnpm is not suitable for your Docker setup, you can explore other package managers like npm or yarn that might better align with your requirements.

Ultimately, the decision comes down to the specific needs of your project and the trade-offs you are willing to make. It's crucial to choose a setup that maximizes efficiency while ensuring seamless integration with Docker containers. Happy coding! 🚀💻 #Docker #pnpm #npm #yarn #containerization #development #efficiency

Collapse
 
turanmahmudov profile image
Turan Mahmudov

Man, you are literally using chatgpt to reply to a comment. Stop it already.

Thread Thread
 
kristiyan_velkov profile image
Kristiyan Velkov

Thank you for your comment.
Sorry,to say that hope you will understand me right 👍

Who are you to tell me what I need to use ???

If you like what the article brings to the public fine, if note sorry but don't spam.

Best regards,
Kris

Collapse
 
nicolasdanelon profile image
Nicolás Danelón

there is a package named please-use-pnpm that you could install ^^ the readme is pretty self-explanatory :)
great article ;) will mark the content as high quality on the mod panel

pnpm Is life
pnpm is love

Collapse
 
kristiyan_velkov profile image
Kristiyan Velkov

Thank you for the suggestion! 🙏 I checked out the "please-use-pnpm" package, and it looks promising! 😄 I'll definitely give it a try and explore its features further. Your article was a great read and provided valuable insights! 📚 I'm glad to hear you found the content to be of high quality, and your positive feedback motivates me to keep sharing helpful tips and tools with the community. 🌟

And yes, pnpm truly is life and love! ❤️ I couldn't agree more! It's a fantastic package manager that simplifies the workflow and saves so much space. Happy coding with pnpm! 🚀💻 #pnpm #pleaseusepnpm #package_manager #developerlife #happy_coding

Collapse
 
sushruth profile image
Sushruth Shastry

Yarn 2+ goes beyond this a bit on performance and space optimization. It has its fair share of compatibility issues but it is way better when it works. And it does mostly work.

Collapse
 
kristiyan_velkov profile image
Kristiyan Velkov

Absolutely! Yarn 2+ brings significant performance and space optimization improvements over previous versions, making it a powerful choice for managing dependencies in modern projects. The Plug'n'Play feature in Yarn 2 eliminates the need for a node_modules folder, which results in reduced disk space usage and faster installation times.

While Yarn 2+ has made remarkable progress in terms of performance and optimization, like any tool, it may have some compatibility issues with certain projects or packages. However, the Yarn team has been actively working on improving compatibility and addressing these issues to ensure a smoother experience for users.

When Yarn 2+ works well with your project, it indeed provides an efficient and streamlined dependency management solution, improving overall development productivity. It's great to hear that you've had mostly positive experiences with it.

As with any technology choice, it's essential to consider the specific needs and requirements of your project to determine the best package manager that aligns with your workflow and goals. Whether it's Yarn, pnpm, npm, or any other tool, staying informed about their strengths and limitations empowers developers to make well-informed decisions for their projects.

Keep exploring and experimenting with the tools that work best for you, and happy coding! 🚀💻 #Yarn #dependency_management #performance #optimization #development #happy_coding

Collapse
 
tillt profile image
Till

When ur comparision doesn't even mention audit capabilities ur either a kid which started programming 3 days ago or ur plain bad.

Collapse
 
nafg profile image
nafg

Or you think you chatgpt can ghost write for you