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.jsvar 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
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
How to upload files to the server using JavaScript
In this tutorial we are going to see how you can upload files to a server using Node.js using JavaScript, which is very common. For example, you might want to…
How to combine multiple objects in JavaScript
In JavaScript you can merge multiple objects in a variety of ways. The most commonly used methods are the spread operator ... and the Object.assign() function. How to copy objects with…
How to Track Flight Status in real-time using the Flight Tracker API
The Flight Tracker API provides developers with the ability to access real-time flight status, which is extremely useful for integrating historical tracking or live queries of air traffic into your…
The Payment Request API: Revolutionizing Online Payments (Part 2)
In the first part of this series, we explored the fundamentals of the Payment Request API and how it simplifies the payment experience. Now, let's delve deeper into advanced features…
The Payment Request API: Revolutionizing Online Payments (Part 1)
The Payment Request API has emerged as the new standard for online payments, transforming the way transactions are conducted on the internet. In this two-part series, we will delve into…
Let's create a Color Picker from scratch with HTML5 Canvas, Javascript and CSS3
HTML5 Canvas is a technology that allows developers to generate real-time graphics and animations using JavaScript. It provides a blank canvas on which graphical elements, such as lines, shapes, images…
How do you stop JavaScript execution for a while: sleep()
A sleep()function is a function that allows you to stop the execution of code for a certain amount of time. Using a function similar to this can be interesting for…
Mastering array sorting in JavaScript: a guide to the sort() function
In this article, I will explain the usage and potential of the sort() function in JavaScript. What does the sort() function do? The sort() function allows you to sort the elements of…
Infinite scrolling with native JavaScript using the Fetch API
I have long wanted to talk about how infinite scroll functionality can be implemented in a list of items that might be on any Web page. Infinite scroll is a technique…
Sorting elements with SortableJS and storing them in localStorage
SortableJS is a JavaScript extension that you will be able to use in your developments to offer your users the possibility to drag and drop elements in order to change…
What is a JWT token and how does it work?
JWT tokens are a standard used to create application access tokens, enabling user authentication in web applications. Specifically, it follows the RFC 7519 standard. What is a JWT token A JWT token…
Template Literals in JavaScript
Template literals, also known as template literals, appeared in JavaScript in its ES6 version, providing a new method of declaring strings using inverted quotes, offering several new and improved possibilities. About…