开发者

Node.js has no method 'sendHeader'

Node.js has no method 'sendHeader'

Installation copy is from git clone git://github.com/joyent/node.git

Is install inside ubunti lucid server as Amazon EC2 AMI file.

The simple say hello via command output is working.

But, when output to browser, it fail to works.

Guys, any idea to fix it?

I hope to use node.js, but seems it is not ready for production usage yet.

ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ node hello_world_server.js
Server running at http://localhost:8080/

/home/ubuntu/Desktop/node/test3/hello_world_server.js:5
    response.sendHeader(200, {"Content-Type": "text/html"})开发者_运维百科;
             ^
TypeError: Object #<ServerResponse> has no method 'sendHeader'
    at Server.<anonymous> (/home/ubuntu/Desktop/node/test3/hello_world_server.js:5:14)
    at Server.emit (events.js:45:17)
    at HTTPParser.onIncoming (http.js:1081:12)
    at HTTPParser.onHeadersComplete (http.js:87:31)
    at Socket.ondata (http.js:980:22)
    at Socket._onReadable (net.js:654:27)
    at IOWatcher.onReadable [as callback] (net.js:156:10)
ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ node -v
v0.5.0-pre

Code to run

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

http.createServer(function (req, res) {

  setTimeout(function () {

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

    res.write('<br/><strong>&nbsp;&nbsp;&nbsp;&nbsp;Hello World!</strong>');

    res.end();

  }, 2000);

}).listen(8000);

sys.puts('Server running at http://127.0.0.1:8000/');


If you are following the NetTuts tutorial, try:

response.writeHead() 

instead of

response.sendHeader

and

response.end() 

instead of

response.close()


The function is probably called writeHead(). "Probably", because I don't know your code and what libraries you load.

http://nodejs.org/docs/v0.4.1/api/http.html#response.writeHead

Hardly no one uses node.js for a complete webserver, but for sub-functionality, e.g. chat server it's already in production use on quite a few sites.


It's "setHeader", not "sendHeader".

And no, node is not ready for production use. That doesn't stop a lot of people from using it, but even they'll tell you that they're a little crazy for doing so.

edit — the other answers may be right, that it may be you're looking for "writeHead()". Since all I'm doing here is looking at the quite lovely node.js documentation at nodejs.org, I'm forced to wonder whether you've done that yet yourself.


I believe the method is writeHead()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜