Cheat Sheet - NodeJS and NPM

Cheat Sheet - NodeJS and NPM

Installation

NodeJS version 14:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install nodejs

NodeJS version 16:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs

NodeJS version 18:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

Check:

node -v
npm -v

Global Packages

sudo npm i -g nodemon

Internal watch failed: ENOSPC

During development and using nodemon or any other such package, you may encounter an error:

Internal watch failed: ENOSPC: System limit for number of file watchers reached

To solve this issue just increase inotify watchers by:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

App package version in shell

To get the NodeJS app version from package.json in the Linux shell you can use the following command:

APP_VERSION=$(npm pkg get version --workspaces=false | tr -d \")