user1765884 user1765884 - 2 months ago 24
Node.js Question

node.js 8080 port isn't listening

I'm following the node.js tutorial in here,

http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/

this is the code,

var sys = require("sys"),
http = require("http");

http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.close();
}).listen(8080);

sys.puts("Server running at http://localhost:8080/");


in here, it says run like this url,

server's ip:8080/

but if i do this,

it just shows, cannot connect to this url.

i opened 8080 port in the server.

===========================

I'm assuming something is screwed up with codeigniter url helper...

Answer

The tutorial may be using an incorrect or deprecated method. Replace

response.sendHeader(200, {"Content-Type": "text/html"}); 

with

response.writeHead(200, {"Content-Type": "text/html"}); 

and

response.close();

with

response.end();
Comments