Blog

How to install node.js on your shared server?

Tags: Server Management

Published on: February 1, 2019 by Daniel Wren

How to install node.js on your shared server?

Scenario:

Most of the good web hosting companies now a days, do provide node.js support. You could check whether it is already running by getting a shell access from the provider and running the following commands:

# which node

/usr/local/bin/node

# which npm

/usr/local/bin/npm

As a tip, when you write a node.js script and make it executable, donʼt give the absolute path, instead use the line as below:

#!/usr/bin/env node

This way you can ensure that the nodemon / forever / node in your $PATH variable is taken.

If you are getting a successful answer similar to below, you are good to go. If not, you will have to install node.js using nvm, which is Node Version Manager.

GitHub – creationix/nvm: Node Version Manager – Simple bash script … You would have to restart the terminal or re-read the profile. On successful installation, you would get the version, using

nvm - -version

If you are encountered with an error, on installation of

npm install node

like below, you are stuck. Things may not move forward easily. This is normally as a result of resource limitations imposed by the host.

bash: fork: retry: Resource temporarily unavilable

While running your first node.js app, you will also have to make sure that whatever port your app, tries to open and make available for others to open, is accessible from outside. Most web hosting companies will have restrictions imposed on ports. Another chance is that your application is opening a port, say 3000, but yet another node.js app is running on the same. How do you figure it out whether port 3000 is open ? You can do a telnet localhost 3000 (considering port number is 3000), and if you are getting a response, as below, that means port is open. It also implies to try another port 🙂

telnet 127.0.0.1 3000

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

quit

Avoid running port scanning to know the open ports and you may risk your IP to be blocked by the firewall. You can access the app, by calling your website name. All you have to do is, write a rewrite rule, similar to the one below and put it in your .htaccess.

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

Now you are done with your node.js application hosting.

Let us take care of your servers 24/7/365. Get rid of all the hassles of server management.

Category : server, Sever management

Daniel Wren

Daniel Wren

An innovative and dedicated IT professional who is very curious to solve and find solutions to seemingly difficult tasks.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend