Reputation: 2577
I ran some node.js tests on my windows machine and everything worked well. Now I installed node on my debian remote machine, and Im trying to run a simple http server:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
I execute using SSH: node server.js
Now when I go to my server ip http://xxx.xxx.22.127:8888 the server times out.
What am I doing wrong? I tested with some simpler scripts and node.js appears to be installed properly. Can it be a firewall issue, or maybe I should add a host-ip or sommit?
Side question: when I run node server.js
in putty i cant type anymore, how do I return to the commandline? :)
EDIT: My iptables info
Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:5900
ACCEPT tcp -- anywhere anywhere tcp dpt:8888
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain fail2ban-ssh (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Upvotes: 0
Views: 629
Reputation: 75317
There may be a software firewall (iptables
for instance) or a hardware firewall in place which is stopping requests to 8888
from being received. The only way to resolve this is to dig into your server configuration/ network architecture to track down the problem. For instance, you can use iptables -L
if you're using iptables to see what rules are enforced currently.
There could also be another application already listening on 8888
, but I believe this throws an error rather than failing like this, so I doubt this is the problem. One way to check this would be via netstat -a
.
Needless to say, I am saying the code you've got should work fine, and it's a problem with your server set-up that is causing this.
Side answer: Use nohup
and &
like so; nohup node server.js &
, although you should look at installing a module such as forever
, and then use forever start server.js
; forever
has the additional benefit of restarting your node process automagically if it crashes.
Upvotes: 2
Reputation: 12265
What am I doing wrong? I tested with some simpler scripts and node.js appears to be installed properly. Can it be a firewall issue, or maybe I should add a host-ip or sommit?
I see nothing wrong with the script itself. Try to debug it with telnet
.
Side question: when I run node server.js in putty i cant type anymore, how do I return to the commandline? :)
node server.js &
(also see man nohup
)
Upvotes: 0