I have Godaddy Shared Web Hosting I need to host node.js website can host site?

44,854

Solution 1

Yes this is possible. Somehow I have never seen anyone actually answer this question correctly. This works with the most basic shared hosting plans. I have successfully been able to set it up a couple different ways. I think the second is probably what you want :

1. cgi-node http://www.cgi-node.org/home

Basically this replaces PHP on the lamp stack. You can run javascript through node like you would run PHP. This has all the same functionality of node js but is only really geared towards template rendering.

    <html>
    <body>
     <?
       var helloWorld = 'Hello World!'; 
       write(helloWorld + '<br/>'); 
     ?>
     <?= helloWorld ?>
    <br/>
    <b>I can count to 10: </b>

    <?
      for (var index= 0; index <= 10; index++) write(index + ' ');  
    ?>
      <br/>
      <b>Or even this: </b>
    <?  
      for (var index= 0; index <= 10; index++) { 
    ?>
        <?= index ?> 
    <? } ?>

    </body>
</html>

OR

2. Standalone Server (this works with NameCheap hosting and GoDaddy shared hosting)

In your shared hosting account you will need SSH in order to do this. So you may need to upgrade or request SSH access from their customer support. Download the latest NodeJS https://nodejs.org/en/download/. The shared hosting is probably in linux 64 bit. You can check this on linux or unix by running :

uname -a

Download the Linux binaries and put the bin/node (and the bin/npm file if you want to use npm on the server) file from the download in /home/username/bin/ (create the bin folder if it doesn't exist) on the server. Put permissions 755 on the node binary. So you should have a new file here :

/home/username/bin/node

Open up the .htaccess file in /home/username/public_html and add the following lines :

RewriteEngine on
RewriteRule  (.*)  http://localhost:3000/$1  [P,L] 

Create a file in /home/username/public_html and just call it app.js. Add the following lines in that file :

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('NodeJS server running on Shared Hosting\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

SSH into the server run these commands :

cd /home/username/public_html
which node # this should return ~/bin/node
node app.js & # This will create a background process with the server running

If you can get this set up right this will save you a ton of money in the long run as opposed to using something like AWS or Heroku etc.

Solution 2

Yes, this is possible on even the cheapest shared hosting tier. @nebulr instructions are correct. Here is a slightly updated and expanded version for noobs like me.

(1) Enable SSH on your shared hosting account:

Log into your GoDaddy hosting and turn on SSH Access (on the Dashboard, it's in "Settings" on the bottom right). Take note of the cPanel login username and change the password if you don't remember it. Note that you also may need to create keys in CPanel, under "Security" and "SSH Access".

(2) Install the nodejs program itself:

Download the Node.js binaries from https://nodejs.org/en/download/ Specifically you'll want the Linux x64 version (direct link https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz)

Unpack this .tar file on your computer and look inside for the bin folder (on a Mac you may need a program such as The Unarchiver to unpack it). The bin folder will have a file called "node" that's about 40Mb. This "node" file is the only thing we're going to use in this package.

Using the CPanel File Manager or FTP program, create a folder on the server called "bin" in /home/yourUserName/ and give it permissions of 755. Note this is NOT inside public_html.

Upload the "node" file to /home/yourusername/bin/

(3) Create a simple nodejs script:

Open a text editor (like Sublime) and create a new file called "app.js" (or whatever):

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('NodeJS server running on Shared Hosting\n');
});

server.listen(port, hostname, () => {
  console.log('Server running at http://${hostname}:${port}/');
});

Note that this is just the basic server app from https://nodejs.org/en/docs/guides/getting-started-guide/

Open your CPanel File Manager or FTP program, and upload the app.js file to /home/yourusername/public_html/

(4) Modify the .htaccess file:

Use your FTP program to add these lines to the .htaccess file:

RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Note that the .htaccess file is probably blank by default. Also note that you can use nano, vim, or emacs in SSH to edit the .htaccess file if you're brave or 1337.


(5) Start the node server:

SSH into the godaddy server by opening Putty (Windows) or Terminal (Mac) and at the command line type: ssh [email protected] (where username is your hosting account's cPanel login) The server should respond with [email protected]'s password: which is where you enter the cPanel login password.

Note: If it's your first time SSH'ing to the server, you'll get a message: The authenticity of host 'X.X.X.X' can't be established. RSA key fingerprint is XXXX. Are you sure you want to continue connecting (yes/no)? Type yes and continue on.

Navigate to /home/yourUserName/public_html/ by typing cd public_html. Start the node server script by typing: node app.js & In a couple seconds you should see the message: Server running at http://127.0.0.1:3000/

(6) Check it out:

Open a web browser and type your website's URL. You should get a white page with the text NodeJS server running on Shared Hosting or whatever message you put in line 9 of app.js above. Note that you can't use the IP address on a shared hosting account, you need to use the domain name.

Solution 3

I installed node on godaddy shared hosting with multiple domains by:

  1. SSH to the godaddy server

  2. Install nvm in the home folder

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash  
    
  3. nvm install 10.14.0 (or the preferred node version) Note: if you get nvm command not found when doing $nvm --version, just close and restart the SSH terminal

  4. In the folder of the site you want to run the node app, add the .httaccess file

    ~/public_html/site folder/.htaccess
    

    RewriteEngine on

    RewriteRule (.*) http://localhost:3000/$1 [P,L]
    

note: .htaccess can be used to target individual folders and changes take effect immediately without having to restart the server.

  1. Run your app.js or node server in the site folder as @nebulr indicated

    $node app.js &
    

Solution 4

One other way to do this is via NVM. First get connected to your server using SSH. Then there's a curl command allowing you to install NVM through a bash script :

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

For me, two additional steps were necessary :

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Sources:

Solution 5

As @nebuir states it is possible to run your node.js developed app using GoDaddy's shared host option because I just did it. The .htaccess portion is extremely key to making this work. The only other line I needed to add was

RewriteRule ^index.html.var$ http://www.yoursite.com:3000/$1 [L,P,QSA]

before

RewriteRule  (.*)  http://www.yoursite.com:3000/$1  [P,L]
Share:
44,854

Related videos on Youtube

Flutter
Author by

Flutter

Worked on challenging projects which enabled our team to Lean, Explore, Implement new and challenging things and play roles in almost every aspect of the software development, which includes: Requirement understanding Web App and Mobile App development and complete it as per SDLC Wireframe/mockup design Deploy Apps on Cloud, Hosting Or AppStore &amp; PlayStore Technical content writing and documenting things implemented in the application Client communication Digital Marketing implementation through Programming and Get an insight into users behaviors

Updated on July 09, 2022

Comments

  • Flutter
    Flutter almost 2 years

    Anyone have an idea to host a site or reference for how to install a node server on Godaddy. We have Godaddy shared hosting which provides full Cpanel and looking to customize this shared hosting. What is the step to follow and Is we can able to customize this kind of hosting with editing in the Cpanel setting?

    I had tried to host the Node.js website bu not able to get up and running it's shows the pure HTML coded website, not User Interface.

    • Flutter
      Flutter over 3 years
      We got the solution as GoDaddy enable the Node and Python Hosting on the Shared plan.
    • SemperFi
      SemperFi about 3 years
      Hey Bhavik. Can you share the link. They are saying to take a VPS and not shared hosting. I am a bit confused with the same. Facing the same questions as you are
    • nidhi
      nidhi about 3 years
      in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?
  • Flutter
    Flutter over 7 years
    Yes, I have Shared hosting on Godaddy.
  • Flutter
    Flutter over 7 years
    Is their any tips i can run node.js site on my shared hosting ?
  • Manish Singh
    Manish Singh over 7 years
    @BhavikLimbani: Not shared hosting. It's their own node instances which runs on VPS.
  • ee0jmt
    ee0jmt almost 6 years
    Thanks nebulr for this, it has been a massive help! One question, when I close my ssh terminal it stops the node app from running. How do I start the app through cpanel to keep it running.
  • nebulr
    nebulr almost 6 years
    Thats odd the node app.js & should take care of that since the & indicates it should run the application in the background
  • ee0jmt
    ee0jmt almost 6 years
    You're right! sorry I missed the & from the end. Thanks massive help!
  • drwbns
    drwbns over 5 years
    I am following the guide at: ferugi.com/blog/nodejs-on-godaddy-shared-cpanel I almost have everything configured but I am having a problem with the .htaccess portion. When adding it for my site, I get an Internal server configuration error. I can run my node app in SSH bash just fine so I know it's working. Any ideas what could be wrong?
  • nebulr
    nebulr over 5 years
    @drwbns do you have any error codes I can see?
  • drwbns
    drwbns over 5 years
  • alecellis1985
    alecellis1985 over 5 years
    Did not work at all
  • jainashish
    jainashish about 5 years
    Awesome - It is working. You just saved me lots of money I would have spent on cloud.
  • Vikash Kumar
    Vikash Kumar over 4 years
    I talked to godaddy guys . they said ssh access is not provided with shared hosting
  • Walter M
    Walter M over 4 years
    Thank you for this! My only concern is...how do you stop it? I can't seem to stop the server. Any solution?
  • Austin Leehealey
    Austin Leehealey about 4 years
    Thank you so much, but how do you make this work with https? I have been trying for days. Is there any simple solution?
  • Mohit Prakash
    Mohit Prakash over 3 years
    How much stable is this process ? If traffic increase then it will be stable to crashed? @nebulr
  • dipenparmar12
    dipenparmar12 over 3 years
    in step 3. throws error: node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by node) (Goddady shared hosting server)
  • Declan Nnadozie
    Declan Nnadozie over 3 years
    I cannot route. Like localhost/dance works. But domain.com/dance goes back to the home page
  • Ravgeet Dhillon
    Ravgeet Dhillon about 3 years
    So so good. Outstanding!!!
  • Nakul Tiruviluamala
    Nakul Tiruviluamala about 3 years
    What is the website URL? Do I go to a subdirectory? I'm afraid that my existing Wordpress page will disappear if I do this...
  • Lint
    Lint about 3 years
    will it be able to install NPM packages ?
  • nidhi
    nidhi about 3 years
    in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?
  • nidhi
    nidhi about 3 years
    in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?
  • stromyc
    stromyc about 3 years
    ssh is available with shared hosting on godaddy.
  • stromyc
    stromyc about 2 years
    Walter to stop the process from running you would open the cpanel terminal and type 'pkill node' that will stop all node processes from running.