Setting up Node Server on Linux

Aman Chourasiya
Last Updated: May 13, 2022

Introduction

Node.js is a JavaScript runtime framework built on Chrome's V8 JavaScript engine for quickly building fast and scalable network applications. Node.js is lightweight and efficient because of its event-driven, non-blocking I/O approach. That's why Node.js is ideal for data-intensive real-time applications that operate across multiple devices.

You can install a Node server on Ubuntu using two methods. 

  1. Ubuntu Official Repository to install node.js
  2. NodeSource Repository to install the latest version of Node.js

 

Install the Node server: Ubuntu Official Repository

Node.js is available in Ubuntu's Official repository and can be installed with only a few keystrokes. To install Node.js on your Ubuntu operating system, follow the steps below.

 

Step 1

Open your terminal (Ctrl + Alt + T) and run the following commands - 

sudo apt install nodejs

Enter your password and hit Enter.

 

Step 2

Verify the installation using the following command -

node -v // You can also use this command: node -version.

You should see an output mentioning the Node.js version.

 

Important: Now, you have installed the Node server in your Ubuntu system. However, it is highly recommended to install NPM (Node Package Manager) alongside Node.js. 

NPM is the package manager for the Node JavaScript platform. It is used for managing various server-side dependencies. It installs modules so that the Node server can find them and intelligently resolves dependency issues.

Step 3

You can install npm using the following command - 

sudo apt install npm

 

Step 4

Verify the installation - 

npm -v

 

You have successfully installed the Node server and NPM in your ubuntu system.

 

Install the Node server: NodeSource Repository

The NodeSource repository contains the most recent version of Node.js. To install Node.js on Ubuntu using NodeSource Repository, follow the steps below.

 

Step 1

Open your terminal or press Ctrl + Alt + T and use the following commands to update and upgrade the package manager:

sudo apt-get update
sudo apt-get upgrade

 

Step 2

Install the python dependencies.

 

sudo apt-get install software-properties-common

 

Step 3

Add Node.js archives to your system. These archives will be extracted to install the Node server.

 

# Installing Node.js v17.x.
curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
# to install previous versions of Node.js, say v16.x, replace setup_17.x with setup_16.x

 

Step 4

Use the command given below to install both the Node Server and npm in your Ubuntu system.

 

sudo apt-get install -y nodejs

 

Step 5

 

Verify the Node server installation - 

node -v

 

Step 6

 

Verify the npm installation - 

npm -v

 

You have now successfully installed node server and npm on your system.

 

Frequently asked Questions

Q1. Does node js work on Linux?

 

Ans: Node.js is an open-source JavaScript runtime environment for building server-side and networking applications. The platform runs on Linux, macOS, FreeBSD, and Windows.

 

Q2. How do I run a node program?

 

Ans: To launch a Node.js program, use the node globally accessible command (once you've installed Node.js) and specify the file's name you wish to run. Make sure you're in the same directory as the app before performing the command.

 

node my_file.js

 

Q3. How do node js servers work?

 

Ans: Node.js is a JavaScript runtime environment that uses a "non-blocking" technique to serve requests to achieve low latency and high throughput. To put it another way, Node.js does not spend time or resources waiting for I/O requests to complete.

 

Q4. Is node js a server side language?

 

Ans: Node.js is an open-source server-side Javascript run-time environment built on Chrome's JavaScript Engine(V8). Node.js is used for building fast and scalable applications and is an event-driven, non-blocking I/O model.

Key Takeaways

In this blog, we learned how to install Node Server and NPM on a Linux machine. NPM is the package manager for Node Server. It is used to install and manage various node modules, which are crucial for handling server-side dependencies. 

Was this article helpful ?
0 upvotes

Comments

No comments yet

Be the first to share what you think