Simplifying the use of multiple NodeJS package managers
Updated at April 19, 2025
Simplify your JavaScript package managers with a shell script. Automate the selection of npm, yarn, pnpm, or bun, enhancing your development workflow.
Introduction
In web development, working on multiple projects often means juggling different JavaScript package managers like npm
, yarn
, pnpm
, or bun
. This can be a hassle. Let me introduce you to a simple shell script, pm
, that takes the guesswork out of package management. Say goodbye to manually typing commands for each project.
The Script
Copy the script below and save it in your shell configuration file (~/.zshrc
or ~/.bashrc
).
If you prefer using an external .sh
file, make sure it’s executable and load it into your shell configuration file.
To make it executable:
chmod +x /path/to/pm.sh
Load it into your shell configuration file:
source /path/to/pm.sh
Once set up, use the pm
command in your project directory to automatically run the correct package manager based on the project’s lockfile.
pm install
Conclusion
The pm
script streamlines your workflow by detecting the right package manager for your project. Add it to your setup, save time, and enjoy a smoother development process.
Lockfile | Command |
---|---|
package-lock.json | npm |
yarn.lock | yarn |
pnpm-lock.yaml | pnpm |
bun.lockb | bun |
Feel free to share your thoughts or suggestions in the gist comments or reach out to me. Happy coding!