开发者

making server in node.js simple hello world

I had installed node by following article https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29

Now i had made a test.js file in c:/cygwin/home/adminstrator/test.js here my node folder is present.

My test.js file is

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/"); 

But in browser if run localhost:8080 or 8.8.8.8:8080 the content is not displaying ("hello world ")

Please suggest what should i do ?

Edit Error while running command

$ node /home/Administrator/test.js
Server running at http://localhost:8080/

/home/Administrator/test.js:5
     response.sendHeader(200, {"Content-Type": "text/html"});
              ^
TypeError: Object #<a ServerResponse> has no method 'sendHeader'
    at Server.<anonymous> (/home/Administrator/test.js:5:15)
    at Server.emit (events.js:27:15)
    at HTTP开发者_如何学编程Parser.onIncoming (http.js:871:14)
    at HTTPParser.onHeadersComplete (http.js:88:31)
    at Stream.ondata (http.js:792:22)
    at Stream._onReadable (net.js:762:27)
    at IOWatcher.onReadable [as callback] (net.js:276:10)


The methods .sendHeader() and .close() don't exist. You wan't .writeHead() and .end() instead.

Reference: http://nodejs.org/docs/v0.3.7/api/http.html#http.ServerResponse

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜