How to host Node.Js application in shared hosting

How to host Node.Js application on shared hosting

I want to host a node.js application on shared hosting. Does anyone have any link or documentation?

+91
web-hosting
Jul 16 '14 at 9:55
source share
5 answers

You can run the node.js server on shared hosting with Linux, Apache and PHP (LAMP). I successfully installed it, even if NPM, Express and Grunt are working fine. Follow these steps:

1) Create a new PHP file on the server with the following code and run it:

<?php //Download and extract the latest node exec('curl http://nodejs.org/dist/latest/node-v0.10.33-linux-x86.tar.gz | tar xz'); //Rename the folder for simplicity exec('mv node-v0.10.33-linux-x86 node'); 

2) Similarly install the node application, for example. jt-js-sample using npm:

 <?php exec('node/bin/npm install jt-js-sample'); 

3) Run the node application from PHP:

 <?php //Choose JS file to run $file = 'node_modules/jt-js-sample/index.js'; //Spawn node server in the background and return its pid $pid = exec('PORT=49999 node/bin/node ' . $file . ' >/dev/null 2>&1 & echo $!'); //Wait for node to start up usleep(500000); //Connect to node server using cURL $curl = curl_init('http://127.0.0.1:49999/'); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Get the full response $resp = curl_exec($curl); if($resp === false) { //If couldn't connect, try increasing usleep echo 'Error: ' . curl_error($curl); } else { //Split response headers and body list($head, $body) = explode("\r\n\r\n", $resp, 2); $headarr = explode("\n", $head); //Print headers foreach($headarr as $headval) { header($headval); } //Print body echo $body; } //Close connection curl_close($curl); //Close node server exec('kill ' . $pid); 

Voila! Check out the demo of the node application on shared PHP hosting .

EDIT: I started the Node.php project on GitHub .

+132
Dec 10
source share

Connect to SSH and follow these instructions to install Node on shared hosting

In short, you install NVM first, then you install the version of Node of your choice using NVM.

 wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash 

Restart your shell (close and restart the sessions). Then you

 nvm install stable 

to install the latest stable version, for example. You can install any version of your choice. Check out node --version for the version of Node you are currently using and nvm list to see what you have installed.

In the bonus, you can easily switch the version ( nvm use <version> )

No need for PHP or any complicated workaround if you have SSH.

+37
Nov 22 '15 at 16:49
source share

I installed Node.js on bluehost.com (shared server) using:

 wget <path to download file> tar -xf <gzip file> mv <gzip_file_dir> node 

This will load the tar file, extract it to a directory, and then rename this directory to the name "node" to make it easier to use.

then

 ./node/bin/npm install jt-js-sample Returns: npm WARN engine jt-js-sample@0.2.4: wanted: {"node":"0.10.x"} (current: {"node":"0.12.4","npm":"2.10.1"}) jt-js-sample@0.2.4 node_modules/jt-js-sample └── express@4.12.4 (merge-descriptors@1.0.0, utils-merge@1.0.0, cookie-signature@1.0.6, methods@1.1.1, cookie@0.1.2, fresh@0.2.4, escape-html@1.0.1, range-parser@1.0.2, finalhandler@0.3.6, content-type@1.0.1, vary@1.0.0, parseurl@1.3.0, serve-static@1.9.3, content-disposition@0.5.0, path-to-regexp@0.1.3, depd@1.0.1, qs@2.4.2, on-finished@2.2.1, debug@2.2.0, etag@1.6.0, proxy-addr@1.0.8, send@0.12.3, type-is@1.6.2, accepts@1.2.7) 

Now I can use the commands:

 # ~/node/bin/node -v v0.12.4 # ~/node/bin/npm -v 2.10.1 

For security reasons, I renamed the node directory to another.

+9
May 31 '15 at 18:11
source share

Hosting A2 allows node.js for its shared hosting accounts. I can guarantee that I had a positive experience with them.

The knowledge base provides instructions for installing node.js using Apache / LiteSpeed ​​as a reverse proxy: https://www.a2hosting.com/kb/installable-applications/manual-installations/install-node-js-on -managed- hosting accounts . Configuration takes about 30 minutes, and it will work with npm, Express, MySQL, etc.

See a2hosting.com.

+5
Sep 12 '15 at 5:49
source share

You should look for a hosting company that provides such a feature, but standard simple static + PHP + MySQL hosting will not allow you to use node.js.

You need to either find a hosting service designed for node.js or buy Virtual Private Server and install it yourself.

+1
Jul 16 '14 at 10:00
source share



All Articles