1

编辑

好吧,它突然神奇地开始工作了。伙计们别管了。你可以忽略这个问题。


编辑 2

我明白为什么了。我没有意识到在输入 node hello_world_app.js 后我必须让它继续运行。我正在打字CNTRL + C以取回外壳。你会认为教程会提到这一点。哦,好吧,“你知道的越多(彩虹切割)”。


我正在尝试遵循节点教程。至此安装顺利。我已经完成了制作 hello world 脚本的部分,但我陷入了困境。

这是创建的 hello world 应用程序:

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000, '192.168.163.129');

// Put a friendly message on the terminal
console.log("Server running at http://192.168.163.129:8000/");

在本教程中,他们将 ip 指向 localhost,但我正在使用外部机器(托管在我的笔记本电脑上但在 vmware 内),所以我输入了用于访问它的内部 IP:

192.168.163.129

那是我用来成功地通过 ssh 进入那台机器的 IP。但它不起作用。当我去:

http://192.168.163.129:8000

我得到服务器未找到错误。

如何让它工作?

当我输入命令时,我还应该提到:

node hello_world_app.js

我得到这个回应:

Server running at http://127.0.0.1:8000

即使在脚本中我指定了不同的 IP。

4

0 回答 0