0

我在 nodejs 中运行一个非常简单的脚本,加载一个静态 html 文件。

var http = require("http");
fs = require('fs');

fs.readFile('./index.html', function (err, html) {
    if (err) {
        throw err; 
    }       
});

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(1994);

每当我启动应用程序时,它都会立即关闭。我在应用程序启动的半秒内看到控制台上的文本,但随后窗口关闭。每次都会发生这种情况。

4

2 回答 2

0

卸载并重新安装nodejs后,再更新问题就解决了。我认为这只是节点对 Windows 来说是新的,有一些未解决的问题。问题是几个月前的问题,所以我忘记了确切的细节。在 Windows 中使用命令提示符 shell 会导致问题(可以想象。)

于 2013-10-22T06:39:28.363 回答
0

您很可能正在使用任何 Node.js 安装附带的 Node.js repl。

当我运行您的代码时,我没有收到任何错误(假设我的目录中有 index.html 并且没有引发错误)。

尝试使用命令通过命令行运行您的代码node yourscriptfilename.js

于 2013-07-10T23:41:10.150 回答