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

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
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.

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.

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 terminal
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.
Run your app.js or node server in the site folder as #nebulr indicated
$node app.js &

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:
https://yoember.com/nodejs/the-best-way-to-install-node-js/
https://github.com/creationix/nvmub.com/creationix/nvm

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]

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

Related

How to host a Gatsby+Node.js project on a shared hosting?

I have a project in gatsby which uses Node.js/express for backend with MySQL.
Now, I know that all I have to do is gatsby build and that will create the static html/css/js files for me in the project/public folder and I can paste all of them in public_html folder and that will work(it is working), but Im confused about the database thing:
My issue is that in the gatsby-config.js when I change the mySql connection from localhost to the hosted db settings such as:
(The commented one is the hosted db configurations)
If I run gatsby develop while uncommenting the code. It says No such DB Error(obviously). So How can I configure the db settings here and also in the gatsby-node.js file to connect the db with the project?
I know this might sound like a dumb question but please help as I'm confused about what to do next.
Thanks.
Okay! Spent a lot of time on this. Hope it will help others.
Static Gatsby site
If you're trying to host a static gatsby site on any shared hosting. By static, I mean just plain gatsby styled pages,
You can do as the gatsby doc says:
Run :       gatsby build        or        npm run build.
According to gatsby:
Gatsby will perform an optimized production build for your site, generating static HTML and per-route JavaScript code bundles.
After this : try npm run serve.
According to gatsby :
Gatsby starts a local HTML server for testing your built site. Remember to build your site using gatsby build before using this command.
serve will test your build files(newly created files in yourprojectroot/public dir)
This will run your project(using the build files) on a test server(localhost:9000) to basically test your build files.
Test this localhost:9000, If everything is working good. You can go to your remote cPanel and paste all your build files into the public_html folder.
Head over to your domain and you're good to go.
Gatsby with MySQL and Node/express
If you are trying to host your gatsby site which works a little with node and mysql as well and you are a newbie in hosting like me, Here's what you'll want to do:
Try both the points mentioned above. (Build your static files and try serve)
Setup your db on the remote as well with the same name dbname, username and password as your local one.
Two extra things:
Now, what you are going to do is to run both the node and gatsby(webpack) servers on the same port (say 8001). So we are going to use only the node server and serve all our gatsby files(build files) as static content to node server.
In your node file, add:
app.use(express.static(path.join(__dirname, 'public')));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname,'public/index.html'));
});
As you are going to run all your gatsby pages through index.html the last get('/*'... (above) will take care of all the pages request. Change the path public according to your remote folder structure
Add the build files along with the node(server connection) file in the public_html folder on remote.
Next add or change your .htaccess file (in the remote) to :
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:8001/ [P,L]
RewriteRule ^(.*)$ http://127.0.0.1:8001/$1 [P,L]
So when you run your node file through the server's terminal, instead of yourdomainname.com:8001 the above mentioned .htaccess will redirect it to yourdomainame.com only
All done.
Your public_html now should contain the build files,a node/express conn file and .htaccess file.
Now, just go to your terminal. cd into public_html and run node yournodefilename.
You can head over to your domain now.
Note : You can use pm2 package to keep your node server always running.
Hope it helps somebody.
You should use environment variables to switch between configurations (locally and production). Environment files are files that store sensitive data such as API keys, tokens, etc, so they must be ignored and untracked to avoid pushing critical data to a public repository.
By default, Gatsby uses .env.development and env.production respectively for gasby develop and gatsby build commands, of course, you can override this behaviour but, assuming the default configuration, you should add the following snippet to your gatsby-config.js:
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
Then, you need to create a .env.development and .env.production in the root of your project with the following content:
DB_HOST:yourHost
DB_USER:yourUserName
DB_PASSWORD:yourPassword
DB_NAME:youDatabaseName
Of course, each file should have different variables if you want to switch between databases or configurations.
Add them to your gatsby-config.js:
connectionDetails:{
host: process.env.DB_HOST
user: process.env.DB_USER
password: process.env.DB_PASSWORD
database: process.env.DB_NAME
}
The final step is to add, in your host, the environment file in order to make them accessible by Gatsby. S3 by Amazon allows to configure them but I guess that it's a common configuration for the hostings.

How can I use (Node) Livereload on a development server in my network

Background: My PHP projects (CakePHP, Wordpress) run on an Ubuntu server in my network, I access them through a development TLD (.dev for example) setup through a local DNS server and I edit the files through a Samba share.
I would like to utilize Livereload for my development, preferably have it running on the server itself. I have basic Node/Gulp knowledge, but haven't been able to get this running.
Livereload (or a middleware server) should proxy the 'real' URLs, making sure all websites run as they would normally and Livereload should be available over the network (so not just localhost, because that runs on the development server)
Desired result:
Livereload runs on my dev server (IP: 10.0.0.1), my project is called helloworld.dev, I browse to 10.0.0.1:3000 on my machine and see helloworld.dev proxied through Livereload. I now edit a CSS file over the Samba share and the CSS is reloaded without a refresh.
I've tried using a few NPM packages, gulp-livereload, livereload, node-livereload, with their provided examples that come with the packages, but haven't been able to get the desired result. They all expect you to run in locally, don't support access to the Livereload URL over the network, cannot proxy the 'real' URLs or require static content.
Can anyone provide an example or 'proof of concept' code of my wish, so I can see where to start?
I found the answer: http://nitoyon.github.io/livereloadx/
This does EXACTLY what I need.
I can run
livereloadx -y http://helloworld.dev -l
open
http://serverip:35729
and I'm ready to roll.
The -y option creates the proxy to the 'real' URL and the -l makes it serve files from local filesystem instead of through its proxy.

noVNC Multiple Localhost Servers

Ive got 4 dev VMs for four projects (all VMware Player VMs w/ubuntu 15.04 host) where each is running VNC (ports 5900, 5901, 5902, 5903) respectively.
I downloaded noVNC and saved to /var/www/html (my apache2 server on same host). Based on the ReadMe I then ran on my terminal
./utils/launch.sh --vnc localhost:5900
I received a missing websockify error, so downloaded it and placed it into the util folder. I then ran the same command and it worked! The terminal told me to Navigate to a url and sure enough I could control my VM.
However -- I'm wondering how can I use noVnc to access all 4 VM's? Is there some simple way to extend the port to a range like in iptables or firewalld?
./utils/launch.sh --vnc localhost:5900-5903
Okay, Ill answer for myself here in case it helps someone in the future...
First, create a token file where each line has a nickname, ip address, and port.
I created a file named token.list where each line looks like:
localhostnickname1: localhost:5900
localhostnickname2: localhost:5901
...
Then I use my terminal to go into the websockify folder so I can see the run file. I issue it the command:
./run --web /path/to/noVNC --target-config /path/to/token.list localhost:6080
Finally, I open my web browser and go to :
http://localhost:6080/vnc_auto.html?path=?token=localhostnickname1
Where localhost1 is the nickname of my first server on the first line of token.list
This link was my reference. If you want to serve this outside of localhost -- change the parameter localhost:8060 from localhost to an IP

Linking in localhost(LAMP)

I am newly(about 1 month) started using LAMP and Bootstrap.
I developed a web-site that worked perfectly until I reinstalled LAMP.
Here my progress:
0. reinstalled LAMP
1. moved my "backup-ed" file to my "localhost" direction
2. I run "chmod 777 *" to each dir and file
3. When I write "localhost" to my browser(firefox) the "index.html" is running
4. When I click the link(say: index)
The browser responds:
http://localhost/undefined
Not Found
The requested URL /undefined was not found on this server.
Apache/2.4.7 (Ubuntu) Server at localhost Port 80
Is there any way to fix this, by the way it's working(linking) perfectly when I write file:///var/www/html/index.html.
The reason why I want to use LAMP is add .php files to handle form.
Thanks
What happens when you do hit http://localhost ?
What exactly do you see?? Tried http://localhost/html
What is exactly your document root as per apache conf?
You might need to check that you are placing your files in the root directoy. It should be in the "htdocs" foler.
/opt/lampp/htdocs/
If all else fails, you can try using xampp which is another free alternative to lamp.
I get this a lot, when your browser looks for a file that is not in htaccess you get a forbidden or unfound error. The way to fix this is to make sure the link you click goes to an accessible URL. Try finding if other links in the page or scripts are overwriting your link.
Finally check if you can access it from another browser, or try to demonstrate the security of your machine. From a public library you can request an Ubuntu CD from canonical, and while you're waiting, you can visually inspect your machine for tampering.

How to install nodejs on Xampp localhost

Been seeing a lot of how to's on how to install nodejs but nothing is at all clear.
So I ask...
Can someone provide a step by step installation guide for installing and using nodejs on a xampp server?
After searching (source), I have found, that it's easier to install Node.js directly (so, no need of XAMP/WAMP):
Install http://nodejs.org/download/
Create a test file (example) C:\myFolder\test.js and put this code in that file:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Open CMD (COMMAND PROMPT) and execute:
node C:\myFolder\test.js
Open this address in your browser: http://127.0.0.1:1337/
Now It's really easy to install and use Node.js even with Apache if you are using Xampp/Wamp etc. Because unlike old days, now Node.js org has created MSI installer for windows.
Below are the steps to install Node.js with Apache. It is assumed that you have already installed xampp
Download windows installer of Node.js from it's site http://nodejs.org/ click on download. Hit the Node.js website and click the big green Install button. It'll detect your OS and give you the appropriate installer. If for some reason it doesn't, click the downloads button and grab the one you need. Run the installer. That's it, you have installed Node.js and, equally, NPM – Node Package Manager – which lets you add all kinds of great stuff to Node quickly and easily.
Note
Keep your Apache and Node ports different. Declare Node port other than 80 or 8080 while creating server in Node because these are the default ports of Apache.
May be these Notes may help someone in future.
1) When Node.js is installed Node and NPM become available globally. Means that you can create your site anywhere on your hard drive and with command prompt go to your directory like in Windows Command prompt
d:/NodeSite/node server.js
and now you can access it via
http://localhost:3000
because your server.js is running with node.
2) Similarly, you can install any Node Package like installing Memcached package or Library
d:/NodeSite/npm install memcached
"NodeSite" is a folder contain your project.
You can see that node and npm have become globals.
It is possible to run NodeJS trough Apache/XAMPP. Great tutorial how to setup httpd.conf / vhosts.conf http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache
<VirtualHost 109.74.199.47:80>
ServerName thatextramile.be
ServerAlias www.thatextramile.be
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
In the end it would be accessible trough port 80 thatextramile.be
I never gave a lot of answers on this site. Because most of the time I'm not an expert however. I had the same issue a while back.
1) You don't really need this XAMPP. Node will create its own http_server so I suggest you just forward calls from XAMPP to the Node app.
2) a good start would be: nodeguide.com/beginner.html
3) I work with PHPstorm which is very nice for Node.js development.
3a) Node.js plugin -> https://www.jetbrains.com/phpstorm/help/installing-updating-and-uninstalling-repository-plugins.html
3b) read this: http://blog.jetbrains.com/webstorm/2014/01/getting-started-with-node-js-in-webstorm/
3c) running: http://blog.jetbrains.com/webstorm/2014/02/running-and-debugging-node-js-application/
3d) Test your app.
You mighht also need this:
4) (MysQl db) https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/
XAMPP and a node.js is two different things, which do not need to work together, nor do they need each other.
XAMPP consists of Apache, MySQL, PHP and Perl.
Where node.js is just like PHP or Apache, so an application.
Node.js can be installed from the website, http://nodejs.org or via the terminal following these instructions:
https://github.com/joyent/node/wiki/Installation
If you want to run javascript from apache you can do it as CGI module. It wont be exacly node.js server and performance because Apache is your server, but you can execute node.js like scripts http://www.cgi-node.org/
You must add a handler to your apache configuration to handle whatever extension files for example .jss via CGI modlue that essentially calls node(.exe) depndeing if linux or windows. I made it work under Bitnami WAMP
It is not possible to install NodeJs on Xammp.
Because Xammp is is simply a tool where Apache,MySql,FileZilla,Tomcat and Mercury server are available. Where you will be able to only configure and use these server.
If you want to install Nodjs on Windows Machine, You will have to install it manually.

Resources