Linux Commands

How to Install and Use Node.js 12 on Ubuntu / Debian / Linux Mint

When you need to build network applications Node.js can be the best runtime engine to use as it is the most powerful JavaScript engine to build applications. You can run Nodejs on various platforms including Linux. In this article you will get the step-by-step guide on how you can install Node.js 12 on Linux.

How to Install of Node.js 12 on Ubuntu / Debian / Linux Mint

You can use the apt package manager to install the Node.js 12 using Terminal on your Linux Mint system and first there are some dependencies that you need to install and for that execute:

sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

After installing the necessary dependencies execute the below mentioned command to install Node.js:

sudo apt -y install nodejs npm

Run the command given below to confirm the installation of Node.js by checking version:

node --version

Now if you want to remove the Node.js in case you installed it through apt then execute:

sudo apt remove --autoremove nodejs -y

Getting Started with Node.js 12 on Ubuntu / Debian / Linux Mint

Follow the steps mentioned below to use the Node.js 12:

Step 1: Execute the command given below to create a file including text you want to display on the server:

sudo nano ab.js

Step 2: Now add the below given code on the file you created:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello and welcome to Linuxhint!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Once you have added the above given code, now save this file, and close it.

Step 3: Execute the below command to make the node.js server run and then click on the server address:

node ab.js

When you click on the server address you will be directed to the file you created on the server:

Conclusion

Node.js is a famous programming environment used to do frontend as well as backend programming. Node.js is extraordinary as it can create advanced applications. You can install Node.js on
Linux Mint by using Apt repository and installation command and using software manager. The guide mentioned in the article also makes you learn the use of Node.js.

About the author

Rafia Amjad

I have a degree in Electronics and love to write. My research and writing emphasize on the most recent innovations in gaming and technology.