Anyone have idea to host site or reference for how to install node server on Godaddy.
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.
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 username@website.com
(where username is your hosting account's cPanel login)
The server should respond with username@website.com'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.
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:
You have two choices to host node app. - Either buy your own VPS server from godaddy or digitalocean, etc.. - Godaddy itself provide the option to run their node instances. please refer https://in.godaddy.com/pro/one-click-installation/node-js
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]
I installed node on godaddy shared hosting with multiple domains by:
SSH to the godaddy server
Install nvm in the home folder
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
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 terminalIn 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.
Run your app.js or node server in the site folder as @nebulr indicated
$node app.js &
来源:https://stackoverflow.com/questions/40146067/i-have-godaddy-web-hosting-i-need-to-host-node-js-website-can-host-site