2011-02-03 2 views
1

Я установил узел по следующей статье https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29делает сервер в node.js простого привет мир

Теперь я сделал файл test.js в C: /cygwin/home/adminstrator/test.js здесь папка моего узла настоящее.

Мой test.js файл

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

Но в браузере при запуске Localhost: 8080 или 8.8.8.8:8080 содержание не отображающее ("привет мир")

Пожалуйста, укажите, что должно я делаю ?

Редактировать Ошибки при запуске команды

$ 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 HTTPParser.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) 
+0

Вы начали Node.js с помощью 'узла/дома/Adminstrator/test.js' команду из Cygwin консоли? – actual

+0

@actual, если я делаю node test.js, он показывает вывод функции sys.puts («Output»). но как запустить в браузере respose.write? – XMen

ответ

3

Методы .sendHeader() и .close() не существуют. Вместо этого вы делаете .writeHead() и .end().

Ссылка: http://nodejs.org/docs/v0.3.7/api/http.html#http.ServerResponse

+0

@ Box9 Но как открыть в браузере? – XMen

+0

@Rahul, извините, я пропустил эту часть. В cygwin type: 'node/home/administrator/test.js', затем направьте свой браузер на' localhost: 8080'. –

+0

@ Box9 не работает, мне нужно установить apache для этого? – XMen

Смежные вопросы