later NPM, hello PNPM
Brandon Andersen
Lead Software Engineer | Specializing in Modern Web Technologies & Scalable Architectures | Driven by Innovation
It's been a nice run, NPM. We had our ups and downs, but it's finally time to start seeing other people.
PNPM is a cool package manager that uses a unique approach to managing dependencies. It creates a single virtual store for all packages, which can then be used across multiple projects. This not only saves disk space but also speeds up installation times by avoiding redundant downloads.
What's also great about PNPM is that it stores only one copy of each package on your disk. So, when multiple projects depend on the same package, PNPM links all the projects to the same file on disk. This reduces disk usage and speeds up installation time. And, if you're worried about unused packages cluttering your disk, don't worry! PNPM has a built-in mechanism to automatically prune them and keep your disk clean.
I love using NVM, but I always find it a hassle to install global packages for each node version. So, heres a shell script that can help with that.
#!/bin/bas
installed_versions=$(nvm ls | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -u)
for version in $installed_versions; do
? ? echo "Installing pnpm for Node.js $version..."
? ? nvm use $version
? ? npm install -g pnpm
done
echo "l8r npm,hello pnpm"
This script iterates through each version of Node.js installed via NVM, switches to that version, and installs PNPM globally using npm. By doing this, you can take advantage of PNPM's benefits across all your Node.js projects.
PNPM is highly compatible with both npm and Yarn. It supports all the features of these package managers, including lockfiles, workspaces, and peer dependencies. PNPM also has a built-in mechanism for resolving conflicts between dependencies.
Have you switched from npm to Yarn or PNPM? PNPM offers some great benefits.