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> Hello World!</strong>');
res.end();
}, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
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.