I want to use node.js on my Ubuntu linode.
I have a basic javascript file 'server.js':
Code:
var http = require("http");
var app = http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.end("HTTP response from Express.\n");
});
app.listen(3000, "localhost");
console.log("Server running at http://localhost:3000/");
I start the 'server.js' package and should be listening on port 3000. But when I point a browser at my linode's ip:3000 there is no response.
I have tried declaring 'server.js' to listen to port 80, and I've also tried redirecting port 80 to 3000:
Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
This same 'server.js' code snip-it works in my local Windows development environment.