Table of Contents
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.
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.
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:
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.
]
tar xvf node-v10.5.0-linux-x64.tar.xz
mv node-v10.5.0-linux-x64 nodejs
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,
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.
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.
]
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.
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.
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.
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.
As the demand for virtual private servers (VPS) continues to grow, businesses and individuals are faced with a crucial decision:…
Web hosting is a large industry, as many other factors help any web hosting provider to form a company. The…
Welcome to the complete guide to WordPress security best practices in 2024. As technology evolves rapidly, implementing strong security measures…
Hey, wanted to learn about web hosting? Or do you want to start a new website and need hosting? Questions…
In today's digital world, the threat of DDoS attacks has become increasingly prevalent. These types of attacks have the power…