8701. Installing Node.js and NPMNode.js and NPM
Tutorial for how to install Node.js and npm on Ubuntu and Mac.
1. What is Node.js
Node.js is a very powerful JavaScript-based framework/platform built on Google Chrome’s JavaScript V8 Engine. It is used to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications. Node.js is open source, completely free, and used by thousands of developers around the world.
NPM is a package manager that makes installing Node ‘packages’ fast and easy.
2. Core Concepts of Node.js
- Blocking and Non-blocking Calls
- Single thread, Event Loop
- Timers
3. Installing Node.js and NPM on Ubuntu
Update your local package index:
$ sudo apt-get update
Install potential unmet dependencies:
$ sudo apt-get -f install
Install Node.js:
$ sudo apt-get install nodejs
Check Node.js version to make sure it has been installed properly.
$ nodejs -v
Install NPM:
$ sudo apt-get install npm
Check NPM version:
$ npm -v
4. Installing Node.js and NPM on RedHat
Enter the following command to download the scripts that are required to set up Node.js:
$ sudo rpm -Uvh https://rpm.nodesource.com/pub_4.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm
Install Node.js:
$ sudo yum install -y nodejs
Check versions to make sure nodejs and npm are both installed properly.
$ node -v // check node.js version
$ npm -v // check npm version
5. Installing Node.js and NPM on Mac
Updates Homebrew with a list of the latest version of Node.
$ brew update
Run the below command to install node.js. Notice that npm will be installed together with nodejs.
$ brew install node
Check versions to make sure nodejs and npm are both installed properly.
$ node -v // check node.js version
$ npm -v // check npm version
Use the following command to update node and npm if necessary.
$ brew upgrade node
6. Verifying Installation
Use ‘Hello World’ application to verify Node.js is installed properly.
Create a file named main.js having the following codes.
/* Hello, World from node.js! */
console.log("Hello, World!")
Execute main.js with node
command.
$ node main.js
If everything is fine with your installation, this should produce the following result:
Hello, World!