How to upgrade Node.js via NPM
There are many utilities which require the latest version of Node.js to run properly until you upgrade to latest version of node.js you will not be able to download those utilities. You can upgrade by downloading the latest image from the nodejs.org or you can follow a simple way to upgrade node.js via NPM to its latest version as shown below.
Upgrade Node.js via NPM on Linux/MAC
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
The value n represents as node helper and the command sudo n stable will upgrade the node to the latest stable version that has been released.
If you desire to install a specific version of node.js version then you can go ahead and type the below command.
sudo n 0.12.2
To check the Node.js version currently installed in you system use the below command
Upgrade Node.js via NPM on windows
Download the “Windows Installer (.msi)” from http://nodejs.org/download/ and follow the installation steps to install node.js. After complete the installation above, the NodeJS and NPM will be upgraded to the latest one automatically.
If you already have the node.js installed then go to node.js command prompt and type the below commands to upgrade to the latest version.
npm cache clean
npm update -g