0

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

My thoughts exactly. Deleted my answer and +1 to this one.
I checked to see if it was used already, now Ill check for the iptables. Im pretty much a noob with Debian, but Ill figure it out. Thanks for both the answer and the side answer
Ill update my post with iptables info. I already tweedled a bit with it before I came to bug you guys with my questions, thats why you see both port 5900 and 8888 mentioned... Still its not working tho
@HansWassink: I'll be the first to admit iptables aren't my strong point. You might find better luck asking this on serverfault.com, as it's no longer a programming question.
Well Ill go and fish this up, and will edit my answer when i find definite proof. thanks so far
|
0

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)

1 Comment

I didnt say there as anything wrong with the script, it works on windows even. I just tried other simpler scripts, with just a console.log for example to see if the installation was correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.