Hi all
i am new to Node.js
i followed the tutorial and typed the following

var sys = require("util"),
    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:1331/");

its running fine while i run it through cmd
but when i open my browser and type the url i.e. http://localhost:1331,
it says
failed to open requested URL

do i have to setup any web server for it??? or Node.js does it itself???

.listen(8080);

Shouldn't it be: http://localhost:8080 ?

changed

listen(8080)

to

listen(1331)

but still having same problem

The file is running when you try to access it through the browser ?

this is the problem, file is not running through browser

it worked,
i changed my code to this

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

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

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

i commented

response.close()

because i was following an old tutorial.
please change this to

response.end()
commented: Thanks for sharing. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.