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 : 1935  
 
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

Validating HTML forms using BULMA and vanilla JavaScript

Today we are going to write about contact forms and how to validate them using JavaScript. The contact form seems to be one of the top features of every basic home…

A FULFILLED PROMISE - Using the FETCH API to make AJAX calls

In this article we talked about what AJAX calls are and how to use them in a traditional way, by using the XMLHttpRequest (XHR) object. In short, thanks to AJAX…

How to use Parallax.js effect on your website

Today, we're going to write about the parallax effect, similar to parallax scrolling, and how to implement it to improve your landing page. In webdev, they say mobile first -…

How to make the website's dark mode persistent with Local Storage, CSS and JS

Recently we wrote about how to do a switchable alternative color mode or theme, a very useful and popular feature to websites. Today’s article is going to be about how…

Making AJAX requests to a REST API using vanilla JavaScript and XHR

Imagine you just build your first static web page and you would like to add some functionality to make it more attractive and generally more usable. Perhaps you would like…

Dark Mode on website using CSS and JavaScript

In today’s article we are going to learn how to build pretty much standard these days on the web pages and that is the alternative color mode and switching between…

JavaScript: Spread and Rest operators

In today’s article we are going to talk about one of the features of the ES6 version(ECMAScript 2015) of JavaScript which is Spread operator as well as Rest operator. These features…

Why You Should Hire Node.js Developer for Your Backend Development

When developers are building a new website, they mainly focus on both frontend and backend development. The frontend code helps create the interfaces through which the app interacts with the…

Javascript: what are callbacks and how to use them.

Today we are going to learn about a concept that is widely used in javascript and that is used quite a lot by today's frameworks, libraries, especially NodeJS. This is…

HTTP Cookies: how they work and how to use them

Today we are going to write about the way to store data in a browser, why websites use cookies and how they work in detail. Continue reading to find out how…

The package managers npm and yarn: main differences

Npm and yarn are package managers that help to manage a project’s dependencies. A dependency is, as it sounds, something that a project depends on, a piece of code that…

The Javascript asign() method to merge and clone objects

In this article, we will be covering Object.assign()method in javascript in detail with examples. A javascript object is a collection of key-value pairs. Keys are also known as properties of object. Keys…

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