When I enter www.example.com:3000
in the browser, I receive this error (where 'example' is the name of my domain)
This site can't be reached - www.example.com took too long to respond.
I have done these things:
- Installed node.js on my GoDaddy shared account
- Created a folder ../public_html/testsite
- Placed two files in that folder: app.js and .htaccess.
- Start webserver with: node app.js
- Go to browser and enter my domain's URL and port:
- Receive the error message above
This post is very helpful, but I still cannot get my set up to work.
These two files are in ../public_html/testsite/
.htaccess
RewriteEngine on
RewriteRule ^index.html.var$ http://www.example.com:3000/$1 [L,P,QSA]
RewriteRule (.*) http://www.example.com:3000/$1 [P,L]
Note: index.html
is the file that normally loads when you visit here
The app.js:
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 + '/');
});
To start the webserver:
> cd ../public_html/testsite
> node app.js
Server running at http://127.0.0.1:3000
In browser, I enter:
www.example.com:3000
I expected to see, in the browser
NodeJS server running on Shared Hosting
Questions:
- Should I use my own godaddy domain address for hostname in
.htaccess
or should it be localhost? - Is the idea to redirect
www.example.com:3000
(in browser) tohttp://localhost:3000
(on GoDaddy server)? - I've tried all sorts of permutations (using my ip address or domain name, different port numbers, etc.)
- I think I am close, but need a few ideas to try!