Skip to main content
Blog

Simplifying the use of multiple NodeJS package managers

Updated at April 19, 2025

Shell
NodeJS
Package manager

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: npm, yarn, pnpm, or bun. It gets old fast. Switch between enough projects and you’ll eventually forget which command belongs where. So I wrote pm, a simple shell script that figures out the right package manager for you.

The script

Copy the script below and save it in your shell configuration file (~/.zshrc or ~/.bashrc).

If you’d rather keep it in an external .sh file, just 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 it’s set up, just run pm inside your project directory. It reads the lockfile and fires off the right package manager automatically.

pm install

Conclusion

The pm script detects the right package manager for your project by checking its lockfile. No more trying to remember which command goes where.

Lockfile Command
package-lock.json npm
yarn.lock yarn
pnpm-lock.yaml pnpm
bun.lockb bun

Feel free to drop your thoughts or suggestions in the gist comments, or just reach out directly.