How to install Nodejs 8 on Ubuntu 18.04

To install Node.js 8 on Ubuntu 18.04

Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on mac os, Microsoft Windows, and Linux.Node.js also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.

Installation

Update the repository. To update the repository files use the following command.

root@linuxhelp:~# apt update
Hit:1 https://deb.nodesource.com/node_8.x bionic InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease               
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease        
Hit:4 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease       
Hit:5 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done                     
Building dependency tree       
Reading state information... Done
29 packages can be upgraded. Run 'apt list --upgradable' to see them.

Download the node packages. Use the Following command to download the node packages from the url.

root@linuxhelp:~# curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -

##Installing the NodeSource Node.js 8.x LTS Carbon repo...

##Populating apt-get cache...

+ apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease                             
Hit:2 https://deb.nodesource.com/node_10.x bionic InRelease                            
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease                     
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease       
Hit:5 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease    
Reading package lists... Done                     
.
.
.
##Run `sudo apt-get install -y nodejs` to install Node.js 8.x LTS Carbon and npm
##You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
##To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn

Install the node packages. You can use the following command to install the node packages.

root@linuxhelp:~# apt install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 29 not upgraded.
Need to get 13.5 MB of archives.
After this operation, 64.0 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_8.x bionic/main amd64 nodejs amd64 8.12.0-1nodesource1 [13.5 MB]
Fetched 13.5 MB in 18s (744 kB/s)                                                      
Selecting previously unselected package nodejs.
(Reading database ... 166393 files and directories currently installed.)
Preparing to unpack .../nodejs_8.12.0-1nodesource1_amd64.deb ...
Unpacking nodejs (8.12.0-1nodesource1) ...
Setting up nodejs (8.12.0-1nodesource1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

Find the version of the node. To verify the version of the node use the Following command

[root@linuxhelp11 ~]# node -v
V8.12.0

With this The method to install Node.js 8 on ubuntu 18.04 comes to an end.

FAQ
Q
What are Node.js modules?
A
Node.js modules are just libraries and third-party pieces of code that developers can use to make their work much faster. If you’re familiar with Ruby, they are the equivalent of gems.

Modules are also the thing that makes Node.js such a great choice. The numbers of modules on npmjs.com, the primary Node.js modules registry, is steadily growing thanks to the really active community
Q
What are Globals in Node.js?
A
Three keywords in Node.js constitute as Globals. These are:

Global – it represents the Global namespace object and acts as a container for all other objects.
Process – It is one of the global objects but can turn a synchronous function into an async callback. It can be accessed from anywhere in the code and it primarily gives back information about the application or the environment.
Buffer – it is a class in Node.js to handle binary data.
Q
Explain chaining in Node.js?
A
Chaining is a mechanism whereby the output of one stream is connected to another stream creating a chain of multiple stream operations
Q
What is the difference between Node.js and Ajax?
A
Node.js and Ajax (Asynchronous JavaScript and XML) are the advanced implementation of JavaScript. They all serve completely different purposes.

Ajax is primarily designed for dynamically updating a particular section of a page’s content, without having to update the entire page.

Node.js is used for developing client-server applications.
Q
What are the functionalities of NPM in Node.js?
A
NPM (Node package Manager) provides two functionalities:

-Online repository for Node.js packages
-Command line utility for installing packages, version management and dependency management of Node.js packages