Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
No Result
View All Result

How to Install Node.js and NPM – Node Package Manager on Ubuntu 18.04 LTS

September 4, 2018
in Tutorials
0 0
Share on FacebookShare on Twitter

In this article we will be going over the general process of how to install Node.js and NPM on an Ubuntu 18.04 machine.

Node.js, which is a popularly known as “Node” is an open source cross-platform JavaScript run-time environment which is built on Google Chrome’s V8 engine that allows server-side execution of JavaScript code.

This simply means that you can run JavaScript code on your machine as a standalone application, free of any web browser which has traditionally been the only place that JavaScript code could run.

Node.js does not have a rendering engine for CSS nor does it have a DOM parser but it does have things you need to run a server like an HTTP library and a filesystem API.

It is mainly used to build back-end server-side applications, but it is also very popular as a full-stack and front-end solution.

NPM, which is short for Node Package Manager, is the default package manager for Node.js and it is currently the world’s largest software registry.

If you need Node.js only for deploying Node.js applications then the simplest option is to install the Node.js packages using apt from the Default Ubuntu repository or from the NodeSource repository in case you need the latest Node.js and npm versions.

If you are using Node.js for development purposes then your best option is to install Node.js using the NVM script.

Although this tutorial is written for Ubuntu the same instructions apply for any Ubuntu-based distribution, including Linux Mint and Elementary OS using their respective package managers.

Step 1. Add the PPA Packages

Node.js package is available in all the LTS and current releases of Ubuntu, however, in some minimal installations, you might not have it installed. As such, we want to install the package’s PPA. You can use the URL below to specify the version of NodeJS you want to install if the PPA package is not already installed on your machine

sudo apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get update
sudo apt-get upgrade

Step 2 – Install Node.js on Ubuntu

Now that you have successfully installed the Node.js PPA package, you can now execute the below command install Node on and Ubuntu using apt-get. This will also install NPM with Node.js. This command also installs all other required packages on your system.

sudo apt-get install nodejs

Step 3 – Verify Installation

If the last command was run successfully, it means you have been able to install NPM and Node.js on your computer. At this point, we will want to check and make sure that the packages have been successfully installed. In the commands below we are going to run the node.js and npm on the command line to make sure that they are accessible to everyone on the machine. We will be using the command that checks the version of Node or NPM that you are running.

Run the command below to check the version of Node.js you are running.

sudo nodejs --version

After this runs, you should see the version of Node.js installed on the computer. For the demo used for this tutorial we are running node 10.0, so you would see the version like what we have below.

v10.0.0

Just like we did for Node.js we are going to do the same for NPM. We just run the npm command in the console and we can see the version.

npm -v 

6.0.0

At this point, we have successfully install Node.js and NPM on our Ubuntu machine. As the last step, we want to test some of the good features of node.js by running a test server. We will start by creating a test file called test-server.js in that test file enter the code snippet below:

//initialize the http server for Node.js
const http = require('http');

//create a server to accept a request and return a response
http.createServer(function (req, res) {

  //sets the response headers to plain text or html
  res.writeHead(200, {'Content-Type': 'text/plain'});

  //send a message to the client
  res.end('Hello World from Dotlayer\n');

//finally specify the port to listen for connections on
}).listen(3000, "127.0.0.1");

// add a debug message to know when the code is executing
console.log('Server running at http://127.0.0.1:3000/');

Once you have successfully added this code to the test file, you can run the command below to start your server.

node test-server.js

You can now point your web browser, either Chrome/Firefox to http://127.0.0.1 and you should see the message on your screen.

In conclusion

In this post, we have shown a basic example of how we can install Node.js and NPM on Ubuntu as well as running a quick web-server using Node.js. As we mentioned before, Node.js can be used for writing complex server-side and serverless applications. If you have any questions or feedback, feel free to comment below.

ShareTweetPin
Previous Post

Five Tips to Designing an Email Marketing Plan

Next Post

How to Build a Customer Satisfaction Survey

Next Post

How to Build a Customer Satisfaction Survey

You might also like

Mint Linux vs Ubuntu: Which is Right For You?

Mint Linux vs Ubuntu: Which is Right For You?

March 12, 2022
Net Neutrality: What is it and Why Should You Care?

Net Neutrality: What is it and Why Should You Care?

March 12, 2022
Solid State Drives – Why You Should Buy One Today

Solid State Drives – Why You Should Buy One Today

March 12, 2022

Machine Learning Algorithms Every Beginner Should Know

January 25, 2022
What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

December 11, 2021
Simple Video Call integration into Website with Jitsi

Simple Video Call integration into Website with Jitsi

May 26, 2020
  • Terms of Service
  • Privacy Policy
  • Careers

© 2021 Dotlayer.com

No Result
View All Result
  • About Us
  • Advertise
  • Blog
  • Careers
  • Contact
  • Contact Us
  • Get Featured
  • Home Layout 1
  • Home Layout 2
  • Home Layout 3
  • Privacy Policy
  • Security
  • Services
  • Subscribe To Dotlayer
  • Terms of Service
  • Write For Us

© 2021 Dotlayer.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In