KodeBLOG

Kode Blog - Inspiring And Empowering Developers.

Home About Us Courses Categories Blog Contact Us

Node.JS installation and Configuration tutorial

Introduction

Node.JS is free and cross platform. It can run on any operating system i.e. Windows, Mac OS, or Linux based operating system.

In this tutorial, you will learn how to download and install Node.JS on the operating system of your choice.

Topics to be covered

We will cover the following topics in this tutorial;

  • Tutorial Pre-requisites
  • How to download Node.JS for your operating system
  • How to install Node.JS on Windows operating System
  • How to install Node.JS on other operating systems
  • Node Package Manager (NPM)

Tutorial Pre-requisites

For you to successfully complete this tutorial, you will need to know the following.

  • Command line / terminal – Node.JS makes heavy use of the command line
  • Active internet connection

How to download Node.JS for your operating system

Downloading Node.JS is simple. You can download it from the official Node.JS website. Load the following URL in your web browser

https://nodejs.org/en/download/

NodeJS Download

You will be presented with all the options for all supported operating systems.

Click on the link that matches the operating system where you want to install. For example, if you are using a windows operating system, click on Windows Installer.

How to install Node.JS on Windows operating System

This section will guide you on how to install Node.JS on a windows operating system.

Once the download is completed, run the setup to install it

You will get the following security prompt if you are installing on windows

NodeJS Download

Click on Run button

You will get the following window

NodeJS Installation

Click on Next button

Install NodeJS

Accept the License Agreement then click on Next button

Install NodeJS

Click on Next button

!Install NodeJS](https://cdn2.kode-blog.com/images/nodejs/nodejsinstallwizard_4.jpg)

Click on Next button

Install NodeJS

Click on Install button

You will get the following window when the installation is complete

Install NodeJS

Click on Finish button

Testing if the installation succeeded

Once you are done with the installation, open the command prompt

Run the following command

node -v

The above command will give you the version of Node.JS that you are running

You should be able to get results similar to the following

How to install Node.JS on other operating systems

Installing Node.JS on other operating systems is not very different from installing in windows. You just need to download the appropriate installer and follow the installation wizard instructions.

Node Package Manager (NPM)

NPM is a package manager for JavaScript. A package is a module that does a specific task. For example, express is a package that is used to build web applications that use Node.JS on the backend. NPM gives us access to a public registry that hosts open source JavaScript packages.

You can use it to find, share and reuse packages. NPM provides a command line tool to download, install, and manage program dependencies. You can also use the package descriptor format to specify which third party packages your module or application depends on.

NPM is installed when you install Node.JS. The official website for NPM is https://www.npmjs.com/

The following image illustrates how developers interact with the NPM registry.

NodeJS Download

If you want to confirm that NPM is installed, you can run the following command in the command prompt window.

npm -v

The above command will give you the version of NPM that you are using.

The following command will display the quick help for NPM

npm -h

Let’s now look at some of the most commonly used NPM command. Note: If you are using Mac OS or a Linux based system, you may need.

NPM usually works with a package.json file to manage module dependencies and other project information.

NPM Common Commands

The following are some of the most commonly used NPM commands

npm install

This command is used to install packages

It has the following syntax

npm install <package name>@<version spec> [options]

HERE, - <package name> specifies the name of the package i.e. restify - @<version spec> specifies the version number of the package that you want to download. If no version is specified, npm will install the latest version of the package. - [options] as the name suggests, this is option. You can use options such as –save to add the dependency in package.json file or -g to install the package globally.

npm uninstall

This command is used to uninstall packages. NPM will try to search and uninstall the module with the specified name.

It has the following syntax

npm uninstall <package name>

npm update

This command will find the latest version of the package and update it. If the package does not exist, it will install it.

It has the following syntax

npm update <package name>

npm config

This command is used to display npm configuration information

The following command will list configuration information

npm config list

You will get results similar to the following

C:\nodejs>npm config list
; cli configs
user-agent = "npm/2.15.5 node/v4.4.5 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\Raven\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\nodejs
; HOME = C:\Users\Raven
; 'npm config ls -l' to show all defaults.

npm list

This command is used to list installed npm packages. If you want to see all the installed packages globally, run the following command.

npm list –global

The above command will all the packages with their dependencies.. If you would like to limit the depth of the information returned, you can run the following command

npm list --global --depth=0

npm init

This command is used to initialize a new project and create a package.json file. Package.json contains meta data about the project. It has the following syntax

npm init

The above command will ask you a series of questions such as the one shown in the image below

Say yes to complete the process. Once you are done, you will have a package.json file with the following content.

{
  "name": "lets-chat",
  "version": "1.0.0",
  "description": "Web based app that lets friends chat in real time",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Rodrick Kazembe",
  "license": "ISC"
}

npm cache clean

This command is used to clear the npm cache

NPM keeps copies of the downloaded packages in the cache to avoid downloading the same package every time you want to it.

You will cover more npm commands as we proceed with these tutorial series.

Summary

In this tutorial, you have learnt how to install Node.JS and the Node Package Manager (NPM). You can now use NPM to install, uninstall, and remove third party modules. We also looked at how to create a p package.json file together with NPM to manage dependencies.

What’s next?

The next tutorial will show you how to create a simple Node.JS hello world application.

If you found this tutorial useful, support us by using the social media buttons to like and share the tutorial. If you didn’t find it useful, please use the comments section below to let us know how we can do better next time.

Subscribe to our newsletter, like our Facebook fan page or follow us on Twitter to get free updates when we publish new tutorials

Tutorial History

Tutorial version 1: Date Published 2016-08-02