I'm trying to set up a simple "Hello world" node.js app.
I've created the following index.js file:
var app = require("express")();
var http = require("http").Server(app);
app.get("/", function(req, res){
res.send("<h1>Hello worlddddd</h1>");
});
http.listen(8080, function(){
console.log("listening on *:8080");
});
When I open up my local console, and perform node index.js
, I get the message "listening on *:8080", as expected. I point my browser to localhost:8080, and I see the HTML page saying "Hello worlddd", as desired.
Now, I'm trying to do the same on my Virtual Private Server, so I can access the same app from different computers, but all I get is connection timeouts. I've followed these steps:
- Install node.js on my VPS
- Install express via
npm install --save express@4.10.2
- Upload my index.js file to the
var/www/html
folder on my server with IP 192.123.123.12 (an example, this isn't my real IP). - Access the server via PuTTY, and run
node index.js
, where I get"listening on *:8080"
, so I know node.js is working. - Now I point my browser to
http://192.123.123.12:8080
and after about 20 seconds, I get the browser error: "The connection has timed out". - I've tried listening to port :80 instead, but I get the error that this port is already in use.
Does anybody know what I'm doing wrong? Am I using the wrong port? Am I pointing to the wrong URL? Do I need to modify my server preferences? (running Apache on CentOS). I've only found dozens of tutorials that teach you how to run a node.js app on your local computer(pointing the browser at localhost:8080), but I need it to run on my remote server so multiple computers can access the same app.