获取Microsoft JScript编译错误

我用first.js运行一段代码

 var http = require("http"); http.createServer(function (request, response) { // Send the HTTP header // HTTP Status: 200 : OK // Content Type: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // Send the response body as "Hello World" response.end('Hello World\n'); }).listen(8124); // Console will print the message console.log('Server running at http://127.0.0.1:8124/'); 

而即时通过gitbash运行它的愿望输出。 但是用js命令提示符会给它提供微软的jscript编译错误。

这里的问题可能来自几个地方。 最可能的安装为基础。

下面的代码(从上面看)

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

当我尝试在浏览器中加载时,会产生积极的结果。 因此我build议如下:

  1. 尝试运行我把代码片段窗口放到全新的目录中的first.js文件中,然后从命令行导航到目录,并使用命令“Node first.js”(不带引号自然)运行该文件。

1.1如果使用纯文本编辑器(记事本++,记事本,崇高等)以外的任何编辑器,确保文件被事实上设置为输出纯文本(骨头移动,但经常被忽略)

  1. 重新安装节点(值得一击)

  2. 如果一切都失败了,并且你安装了npm,input“npm install http”并重新运行你的first.js应用程序

看起来你刚刚在terminal窗口中键入了脚本的名字,因此要求窗口为脚本find正确的解释器。 你应该尝试用nodejs来解释脚本:

 node your-script.js 

不只是

 your-script.js