Cheap Shared Hosting

Instructions to Install and Run Node.js Application

This article depicts how you can install and run the Node.js application on a hosting account. You can utilize Node.js to run your own applications also can host third-persons applications.

There are two preconditions for running Node.js on a hosting account:

Your record must have the ordinary shell (not jailshell) empowered. Sign in utilizing SSH, to figure out which shell your record is utilizing and afterward type the accompanying cmd:

Node.js as of now just deals with servers running CentOS 6 or CentOS 7.

Introducing NODE.JS AND NPM

You can download and introduce Node.js and npm (the Node.js bundle director); only after you confirm that your record meets the established requirements.

To do this, follow these steps:

a. Sign in to your record utilizing SSH.

b. At the cmd prompt, type the following cmds:

cd ~

wget https://nodejs.org/dist/v10.5.0/node-v10.5.0-linux-x64.tar.xz

[

This order downloads the pairs for the Node.js form 10.5.0 LTS (long haul support) discharge. In the event that you download a recent improvement form of Node.js, change the version numbers in the accompanying cmds to coordinate the variant you downloaded.

]

c. To separate the Node.js records, type this cmd:

tar xvf node-v10.5.0-linux-x64.tar.xz

d. Just rename the extracted folder. For more easynodejs name, type this cmd:

mv node-v10.5.0-linux-x64 nodejs

e. To introduce the node and npm binaries, type this cmds( this step may not be necessary for your setup):

mkdir ~/bin

cp nodejs/bin/node ~/bin

cd ~/bin

ln -s ../nodejs/lib/node_modules/npm/bin/npm-cli.js npm

Soon as you run these cmds, Node.js and npm are introduced for you. To confirm this, type these accompanying cmds:

node –version

npm –version

[

The ~/bin directory is in your path by default, which means you can run node and npm from any directory in your account.

]

Also read,

Beginning a NODE.JS application:

After you introduce Node.js, you are prepared to run Node.js applications. In many cases, the steps may change; this does depend upon the application setup.

Technique #1: Utilize npm

Many other and “production-ready” applications, (for example, Ghost) utilize the npm program to begin the application, as mentioned by this cmd:

nohupnpm start –production &

[

The ‘&’ places the cmd out of sight, and the nohupcmd guarantees that the application keeps running regardless of whether you log out of the present terminal session.

]

There must be a legitimate package.json file for the application, for this strategy to work. The package.json file contains project metadata that the npm program peruses to decide how to begin the application, deal with its conditions, and more

[

It would be ideal if you visit https://docs.npmjs.com/records/package.json , to read the official npm documentation for the package.json record.

]

Technique #2: Run Node immediately

For easy applications, or for any application that doesn’t have a package.json document, you can run the node executable immediately and determine the application filename. For instance:

nohup node my_app.js &

Anywho, you lose the advantages of utilizing npm to deal with the application.

As over, the ‘&’ places the cmd out of sight, and the nohupcmd guarantees that the application keeps running regardless of whether you log out of the present terminal session.

Halting A NODE.JS application:

To stop an as of now running Node.js application, type the accompanying cmd:

pkill node

This cmd quickly stops all running Node.js applications.

Incorporating a NODE.JS application with WEB SERVER

You might need to have the option to utilize an internet browser, relying upon the sort of Node.js application you are running. To do this, you have to choose an unutilized port for the Node.js application to tune in on, and thereafter define server rewrite rules which in turn diverts visitants to the application.

The accompanying stages show how to do this:

1.  In a content manager, add the accompanying lines to the .htaccess files in the/home/username/public_html directory, where username is your account username:

DirectoryIndex disabled

RewriteEngine On

RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]

[

127.0.0.1 is the loopback address for localhost. These revamp rules divert approaching HTTP visitants to appeal to the Node.js application running locally on the server.

]

2. Change XXXXX with the port on which your Node.js application exists of both RewriteRule lines.

[

You must choose an unused port somewhere in the range of 30000 and 50000 (included), to run a Node.js application on a managed server.

]

To the .htaccess file, save the modifications; and leave the text editor. Visitants to your site are diverted to the Node.js application tuning in to the predetermined port.

[

On the off chance that your application doesn’t run, the port you picked is being utilized. Check the application log for error codes like EADDRINUSE that show which port is being utilized. In the event that it is, selects an alternate port number, update your application’s config and the .htaccess document, and try once more.

]

MORE INFO:

For more data about Node.js, if it’s not too much trouble visit http://nodejs.org.


Cyril Chakranarayan
Cyril Chakranarayan - I love Travelling, Riding Bikes, and Reading. I am a passionate technology seeker and love to explore continuously evolving technology especially in the Cyber World, Working in the Web Hosting Industry for 10 years.

Recent Posts

The Ultimate Showdown: Linux vs Windows for VPS Hosting

As the demand for virtual private servers (VPS) continues to grow, businesses and individuals are faced with a crucial decision:…

2 weeks ago

Questions to Ask Your Web Hosting Support Team

Web hosting is a large industry, as many other factors help any web hosting provider to form a company. The…

2 weeks ago

How to Secure Your WordPress Site in 2025

Welcome to the complete guide to WordPress security best practices in 2024. As technology evolves rapidly, implementing strong security measures…

3 weeks ago

Unlocking the Secrets of Hosting: Essential Questions to Ask Hostripples

Hey, wanted to learn about web hosting? Or do you want to start a new website and need hosting? Questions…

3 weeks ago

DDoS Attacks: What You Need to Know for Protection

In today's digital world, the threat of DDoS attacks has become increasingly prevalent. These types of attacks have the power…

1 month ago