Node.js is a software development platform based on the open source JavaScript V8 engine used by developers around the world to build scalable and fast web applications.
The main advantage of Node.js is that it allows developers to build server-side applications using JavaScript on the server side, rather than having to use other programming languages. In addition, Node.js is popular for its ability to handle large numbers of concurrent connections without crashing the application.
As you can see, this tool is very useful, so in this tutorial we will explain how to install Node.js on a Ubuntu 20.04 server.
Before we start with the tutorial, do you not have a Cloud server with Ubuntu 20.04? Don't worry! With just one click you can easily deploy it with SW Hosting.
cta:cloud_so_ubuntu_20
Having said that, let's now start this tutorial by explaining the first method or option to install Node.js on Ubuntu 20.04.
Before installing Node.js on your Ubuntu 20.04 server, make sure that all existing packages are updated. To do this, log in to your server and run the following command:
sudo apt update && sudo apt upgrade
info This command will update all existing packages on your server.
Here's how to install Node.js on your Ubuntu 20.04 server.
You can install Node.js from the Ubuntu repositories or from the official Node.js website. In this tutorial, we will install Node.js using the Ubuntu repositories.
Run the following command to add the Node.js repository:
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
After adding the Node.js repository, you can install Node.js and NPM (Node Package Manager) using the following command:
sudo apt install nodejs
To check that Node.js and NPM are installed correctly, run the following commands:
node -v
npm -v
These commands should print the version of Node.js and NPM installed on your server.
Once Node.js is installed, you can create a sample application to see if it works properly. Create a JavaScript file named app.js
:
nano app.js
Copy the following code and save the file.
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, World!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Run the sample application with the following command
node app.js
The sample application should now be available in http://127.0.0.1:3000/
.
If you need to install global Node.js packages, you can do so by running the following command:
sudo npm install -g package_name
Replace package_name
with the name of the package you want to install.
There is a very quick and easy way to set up Node.js. With SW Hosting you can deploy a cloud server with Node.js in just one click. Our One Click Apps give you access to the latest technology in the cloud in a simple and fast way. Forget the hassle and tedious configuration and enjoy an exceptional cloud experience right out of the box.
cta:cloud_app_nodejs
Installing Node.js on Ubuntu 20.04 is a simple process that can be done in just a few steps. With Node.js and its package manager NPM, you have a powerful tool for building scalable, fast applications.
It is important to note that there are other ways to install Node.js, such as using a release manager such as nvm. However, installing via SW Hosting's One Click Apps is a easy and recommended way to install Node.js on an Ubuntu 20.04 system, or any other system.
Finally, we hope this tutorial has been useful and will help you get started with your Node.js project in Ubuntu.