Node.js浏览器错误

我是Node.js的新手 我按照教程,键入以下内容

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

但是当我去我的浏览器,并键入urlie http:// localhost:1331它是无法打开所需的URL

在浏览URL时在cmd中获取以下内容

 TypeError: Object #<ServerResponse> has no method 'sendHeader' at Server.<anonymous> (D:\node_js\hello.js:11:14) at Server.emit (events.js:70:17) at HTTPParser.onIncoming (http.js:1511:12) at HTTPParser.onHeadersComplete (http.js:102:31) at Socket.ondata (http.js:1407:22) at TCP.onread (net.js:354:27) 

看起来你跟着一个过时的教程。 Node API已经改变了。 试试这个例子:

 var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/html'}); response.end('Hello World\n'); }).listen(1331); console.log('Server running at http://127.0.0.1:1331/'); 

它看起来像你正在监听端口8080.要么改变你的URL或您传递到侦听()的端口号。