Nodejs + PNPM ( PERFORMANT NODEJS PACKAGE MANAGER )
How to manage multiple nodejs versions with pnpm?
PNPM is a new node package manager similar to npm and yarn. pnpm is faster as compared to npm and yarn.
PNPM help to reduce the size of the node_module
folder in the project. PNPM is so fast to install the nodejs package from npm.
Everybody uses nodejs in daily life to build projects. So for everyday life, you need multiple nodejs active versions.
NVM is an excellent tool for installing multiple versions of nodejs. However, maybe you do not like nvm or use different package versions, for example, n, nodenv, and asdf.
To install pnpm on a laptop, you do not need to install nodejs firstly. Instead, you can install pnpm and then help of the pnpm, install any nodejs version and manage multiple nodejs versions.
In javascript, there are five prominent nodejs version managers.
Follow youtube tutorial
Questions
- How to install different nodejs version managers with pnpm?
- How to install a specific nodejs version according to the workspace with pnpm?
How to install different nodejs version managers with pnpm?
PNPM provide inbuilt pnpm env use --global < OPTIONS >
command to install nodejs. you can check all OPTIONS with pnpm env --help
command.
Syntax
pnpm env use --global < OPTIONS >
pnpm env use --global lts
command install the LTS version of nodejs- with
pnpm env use --global < version >
command, you install any version of nodejs - with
pnpm env use --global latest
command, you install the current version of nodejs - With
pnpm env use --global < name >
command, you install nodejs by name.
Example
pnpm env use — global lts
pnpm env use — global < version >
pnpm env use — global latest
pnpm env use — global < name >
After installing nodejs with pnpm env
You check the version with node -v
❯ node -v
v18.9.0
How to install a specific nodejs version according to the workspace with pnpm?
You install a particular version of nodejs according to a workspace with pnpm. For installation, you need a .npmrc
file.
Steps
- Create a
.npmrc
file - Initialization the
pnpm init
- Add Script
- Run
pnpm test
Create a .npmrc
file
The first step is to create a .npmrc
file in the root folder.
.npmrc
use-node-version=11.15.0
Initialization the pnpm init
The Initialization of the new project with pnpm init
command. The pnpm init command creates a new package.json file.
pnpm init
Add Script
You can replace scripts with the package.json file.
"scripts": { "test": "node -v"},
Run pnpm test
In the end, you can run pnpm test
command and your output look like this.
Note
In the terminal, you run node -v
in the same working folder and without pnpm, your node -v
version print defiantly in the terminal.
Conclusion
PNPM is a new node package manager and comes with lots of features. The feature pnpm part is memory (space) management, and the second is multiple node version manager.
Developers continuously adapt and learn new techniques for a better future. pnpm is one of them. It is not required. But pnpm helps enhance your working speed.
You can use any other nodejs version manager. However, if you are a beginner, I suggest starting with pnpm. pnpm is very easy as compared to other nodejs version managers.
You can share and follow on Twitter and Linkedin. If you like my work, please read more content on the officialrajdeepsingh. dev, frontend web, and sign up for a free newsletter on the frontend web.