What is NodeJS?

NodeJS is an asynchronous, event-driven JavaScript runtime environment.

How to Install Node.JS On VPS Server Ubuntu
The first good thing about utilizing Node.JS as your back-end platform is its skill to include concurrent connections without over-utilizing I/O operations, thus saving lots of overhead in CPU energy and permitting a lot higher scalability. Moreover, it’s absolutely suitable for all of your favorite JavaScript frameworks, libraries, and extensions, similar to React, JQuery, Angular, and extra.

Prerequisites for installing NodeJS on Ubuntu

This tutorial will assume the next Install Nodejs:

  • Ubuntu 18.04 server (though desktop ought to still work)
  • Non-root person
  • Basic understanding of Command-Line instruments

Let’s Get Started

To start, let’s be certain that the working system is up-to-date.

sudo apt update && sudo apt upgrade -y

When you get introduced with any GUI-style prompts, the defaults are effective 99% of the time.

Subsequent, we’ll need to Install NodeJS. The easiest way to put in is determined by what you need to accomplish, however, I’ll cowl two of the most typical installations.

Install Using Apt

Ubuntu 18.04 apt repositories embody a comparatively latest version of NodeJS that may be put in using apt straight.

sudo apt install -y nodejs

This will also set up npm, the Node Bundle Manager. npm is used to put in node modules, frameworks, apps, and so on. Now you can take a look at the install bypassing the version flag.

node -v
v14.2.0

Checking npm‘s version as well:

npm -v
6.14.4

This is sufficient to start working with Node.JS. However chances are you’ll need to have a more recent model out there or have extra management over the version on the whole– and that’s the place the node version manager comes into play.

Installing using Node Version Manager

For those who favor having extra management over the model put in, and even in use at any given time install Nodejs Version Manager (nvm as referenced in commands) offers that management.

Let’s try that technique.

First, we now have to truly install nvm. The easiest way to put in nvm is from the source. Yow will discover the most recent setup commands for nvm right here, which can be utilized to each setup and update your nvm instance.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

The install script will run, asking you to shut and reopen your terminal to allow nvm. Achieve this, after which you’ll test to verify the command works, and see what nvm version is currently installed.

nvm --version
0.34.0

I extremely encourage you to learn by the assistance textual content of nvm (run nvm –help), because it offers functionality that many will discover terribly helpful. Nonetheless, for now, let’s arrange the most recent version of Node.JS.

nvm install --lts

This can be an easy command to inform nvm to put in the most recent version of the current LTS (long-term help) ver of NodeJS. When you’ve got not beforehand used nvm to put in a NodeJS version, this command will moreover arrange the “default” alias to this version. Should you want to set up a selected version, you may specify the version you need, as nicely.

nvm install 10.10.0

After getting the version you wish to be installed, use nvm to change to that version because of the actively used version.

nvm use 10.10.0 
Now using node v10.10.0 (npm v6.4.1)

or

nvm use default
Now using node v10.16.1 (npm v6.9.0)

Let’s  Started using NodeJS

It’s Great! We’re on our way, now!

For those who’ve made it this far, you’ve possibly already received a concept for what you’re planning to make use of NodeJS for, so get to it! Your NodeJS framework is able to run your app.

Right here’s a demo “howdy world” app, as displayed on the NodeJS getting began web page. Change SERVERIPADDRESS along with your server’s public-facing IP Deal with, or should you’re operating this on an area desktop version of Ubuntu 18.04, you need to use “127.0.0.1” as depicted on the getting began information.

const http = require('http');

const hostname = 'SERVER_IP_ADDRESS';
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}/`);
});

Now you can save this as app.js in any folder on your NodeJS host, then run:

node app.js
Server running at http://SERVER_IP_ADDRESS:3000/

You need to now be capable of navigating to your VPS IP Address on port 3000 and look at the text displayed.

Install FFmpeg on centOS