Understanding & Installing Node.js and NPM

We have been using client side/front end JavaScript to build dynamic pages where we embed the JavaScript code in HTML file, react to events and make AJAX calls for fetching data from the server.

Node.js allows you to write server side and networking applications with JavaScript.

 

What is Node.js?

 

Node.js is an open-source, cross-platform run-time environment that executes JavaScript code server-side. It is build on built on Chrome’s V8 JavaScript engine. It uses an asynchronous event-driven model and is designed for writing scalable internet applications, notably web servers.

 

What is npm?

 

npm is a package manager for node.js.

npm consists of three distinct components:

  • the website: www.npmjs.com allows you to create a profile, create public/private package and share them, browse packages shared by other.
  • the Command Line Interface (CLI): It allows you to interact with npm, you can use it to install and manage node.js modules.
  • the registry: It is a large public database of JavaScript software and the meta-information surrounding it

npm is written in node.js, so you need to install node.js in order to use npm.

 

How to install node.js in Windows?

 

It is suggested that you to install the LTS version of node. Here are the steps to install node.js in windows machine (The screenshots below have been taken in Windows 10 machine):

Step 1: Download the .msi installer 32 bit / 64 bit from the official node.js website https://nodejs.org/en/download/ depending upon your machine.

 

Step 2: Double click the downloaded .msi file to begin the installation.

 

Step 3: Agree to the license agreement and click “Next”

 

Step 4: Select the folder in which you want to install node.js

 

Step 5: In the “Custom Setup” screen, do not make any change unless you know what you are doing; click next.

 

Step 6: Click the “Install” button to start the node.js installation.

 

Step 7: Click the “Finish” button to complete the installation.

 

How to test the node.js installation?

 

To test node.js, open windows command prompt and type 


C:\users\testuser> node -v

It should print the node.js version like “8.11.4”

 

How to install npm?

 

npm is distributed with node.js – it means that when you download and install node.js, npm automatically gets installed on your computer.

node.js and npm are managed by different organizations. It may be possible that installing node did not install the latest version on npm since npm is updated more frequently than node.js.

So, after installation of node; we can check the version of npm installed and if we see that it’s not the latest version we can update it by typing the following 


C:\users\testuser> npm install npm@latest -g

The latest version of npm is printed on the footer of the npm official documentation pages.

 

How to test the npm installation?

 

To test npm installation, type the following in the windows command prompt 


C:\users\testuser> npm -v

It should print the npm version like “6.4.0”

 

How to update node.js?

 

To update node.js, we need to download the new version from the node.js from the official website https://nodejs.org/en/download/ and run the installer again. It will install the new versions of node and npm replacing the old ones.

Instead we can use node version manager (nvm) that ease the process of node and npm updation and also allow to keep multiple versions of node on our machine. This allows us to switch between multiple node and npm versions and test our application in them.  

nvm also solve the permission problem. Node.js install npm in a directory with local permissions which can cause issues when running packages globally.

Here are the links to different nvm :

 

How to uninstall node.js and npm?

 

Uninstalling node.js on windows machine is same as uninstalling any other application on windows machine.

  1. Go to the Windows Control Panel
  2. Select “Programs and Features”
  3. Select Node.js and click the uninstall link.

 

 

Official Websites

node.js: https://nodejs.org/

npm: https://www.npmjs.com/n

Leave a Comment

Back to top