簡體   English   中英

為什么 nodeJS 'Hello World' 示例不起作用?

[英]Why does the nodeJS 'Hello World' example not work?

將一個簡單的 Hello World 示例從此處粘貼到 ubuntu 機器。 但它不起作用。 我從 console.log() 得到輸出,但是將 webbrowser (firefox) 導航到 127.0.0.1:8081 只是輸出

'問題登錄頁面' 連接已重置 與服務器的連接在頁面加載時已重置。

var http = require("http");

http.createServer(function (request, response) {

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

   response.end('Hello World\n');
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');

它出什么問題了?

確保:

  • -運行 npm 卸載 http
  • -運行初始化 -y
  • -運行 npm 我
  • -運行 npm http

如果您已經完成了所有這些,請確保使用 Google,而不是 Bing Explorer 或 Firefox

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM