How to Install Node.js and NPM on Ubuntu 18.04

by Luigi Nori Date: 24-04-2020 node.js javascript js npm


Node.js is a JavaScript platform for general programming that allows users to create network applications quickly. By leveraging JavaScript in both frontend and backend, Node.js makes development more uniform and integrated. Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. runtime for easily building fast, scalable network applications. In this guide, we'll show you how to get started with Node.js on an Ubuntu 18.04 server.

You can add the PPA to your Ubuntu 18.04 LTS systems and install node.js on Linux VPS with a few easy commands. To start the process you should have a non-root user account with sudo privileges set up on your system

 

Add Node.js PPA from NodeSource

Ubuntu 18.04 contains a version of Node.js in its default repositories that can be used to provide a consistent experience across multiple systems. You can select which version you want to install on the system. Add the following PPA's to your system to install Nodejs on Ubuntu.

To get a more recent version of Node.js you can add the PPA (personal package archive) maintained by NodeSource. 

sudo apt-get install curl  curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -  

Or you can use the most recent LTS release available.

sudo apt-get install curl  curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -  

Install the package Version from Ubuntu repositories or from NodeSource PPA

To get this version, you can use the apt package manager. Refresh your local package index by typing:

sudo apt update  
sudo apt install nodejs 
  

If you also want to install npm, the Node.js package manager. You can do this by typing:

sudo apt install npm

This will allow you to install modules and packages to use with Node.js.

After installing node.js verify and check the installed version.

node -v    
v14.2.0  

Check the npm version

npm -v    
8.10.7  

Create a Demo Test Web Server

If you want to test your node.js install you can create a web server with “Hello World!” text. Create a file server.js

nano test-server.js  

and add the following content

test-server.js
  var http = require('http');
  http.createServer(function (request, response) {
      response.writeHead(200, {
			'Content-Type': 'text/plain'
		});
       response.end('Hello World from Noden');  
	}).listen(1333, "127.0.0.1");  
   console.log('Server running at http://127.0.0.1:3000/');
   

Now start the Node application using the command.

  node test-server.js
  debugger listening on port 5858  Server running at http://127.0.0.1:1333/  
  

You can also start the application with debugging enabled with the following commands.

  node --inspect test-server.js    
  Debugger listening on ws://127.0.0.1:9229/428cf97a-a4b6-3158-134b-c1357c9b24c54
  For help, see: https://nodejs.org/en/docs/inspector
  Server running at http://127.0.0.1:1333/  
  

The web server has been started on port 1333. You can access it from http://127.0.0.1:1333/ URL in browser. Now you will need to configure a front-end server for your app.

 

Removing Node.js

You can uninstall Node.js using apt, to remove the distro-stable version, you will need to work with the apt utility at the system level.

To remove the distro-stable version, type the following:

sudo apt remove nodejs

This command will remove the package and retain the configuration files. These may be of use to you if you intend to install the package again at a later point. If you don’t want to save the configuration files for later use, then run the following:

sudo apt purge nodejs

This will uninstall the package and remove the configuration files associated with it.

As a final step, you can remove any unused packages that were automatically installed with the removed package:

sudo apt autoremove 

 

 

 
by Luigi Nori Date: 24-04-2020 node.js javascript js npm hits : 2355  
 
Luigi Nori

Luigi Nori

He has been working on the Internet since 1994 (practically a mummy), specializing in Web technologies makes his customers happy by juggling large scale and high availability applications, php and js frameworks, web design, data exchange, security, e-commerce, database and server administration, ethical hacking. He happily lives with @salvietta150x40, in his (little) free time he tries to tame a little wild dwarf with a passion for stars.

 
 
 

Related Posts

Dates in local format with Javascript

In the articles we have about dates in JavaScript we were missing one about how to create dates in local format with JavaScript. That is to say, being able to…

Formatting hours in Javascript

Continuing with the set of articles that talk about internationalisation elements, like the previous one where we talked about relative dates in JavaScript, we will see in this one how…

Request data with prompt in JavaScript

After having published several articles about how to manipulate arrays and dates, today I will publish a post that some of you will find too basic and others will find…

Relative dates in JavaScript

One of the interesting things about the internationalisation library represented in the Int object is the handling of relative dates in Javascript. This handling allows us to represent a date…

How to access webcam and grab an image using HTML5 and Javascript

We often use webcams to broadcast video in real time via our computer. This broadcast can be viewed, saved and even shared via the Internet. As a rule, we need…

The JavaScript forEach loop

We have already talked about how to handle some of loops  types in Javascript including for, for-in and for-off loops. In the case of today we are going to see how…

What are React Hooks and what problems they solve

Working with React, - and before the release of Hooks in version 16.8 -  there was always the possibility to create components in three different ways based on a number of…

Flattening arrays in JavaScript

When we are handling arrays that are arrays or have multiple dimensions it can be very useful to know how to flatten arrays in JavaScript. That is to say, to…

How to populate an array with random numbers in JavaScript

Some of you might think that what we explained in the article on how to populate an array with numbers, apart from the didactic part, would not have much applicability…

How to populate an array with numbers in JavaScript

Populate an array with numbers in JavaScript The first step is to initialise the array. So today we are going to see a simple way to do it and see how…

Top Javascript Libraries and Frameworks Part 2

What are JavaScript frameworks?   JavaScript frameworks are application frameworks that allow developers to manipulate code to meet their particular needs. Web application development is like building a house. You have the option…

How to Send Email from an HTML Contact Form

In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration