Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  130] [ 4]  / answers: 1 / hits: 18263  / 12 Years ago, thu, june 7, 2012, 12:00:00

I am trying to learn node.js, but I'm having trouble getting the simple server to run on localhost:8888.



Here is the code for server.js:



var http = require(http);

http.createServer(function(request, response) {
response.writeHead(200, {Content-Type: text/plain});
response.write(Hello World);
response.end();
}).listen(8888);


server.js runs without errors, and trying netstat -an | grep 8888 from terminal returns



tcp4       0      0  *.8888                 *.*                    LISTEN


However, when I go to localhost:8888 in a browser, it says that it cannot be found.



I've looked at all the related questions, and nothing has worked so far. I've tried different ports, etc. I know that my router blocks incoming traffic on port 8888, but shouldn't that not matter if I'm trying to access it locally? I've run tomcat servers on this port before, for example. Thanks so much for your help!



node.js version: v0.6.15

OS: Mac OS 10.6.8


More From » node.js

 Answers
35

This code works--I just tried it and navigated to localhost:8888 and saw the expected output.



It's possible that you have a firewall that's too restrictive or you have a bad install of Node.js.


[#85083] Wednesday, June 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shannon

Total Points: 606
Total Questions: 106
Total Answers: 111

Location: Lesotho
Member since Thu, Jun 30, 2022
2 Years ago
;