获得Microsoft JScript编译错误

Pra*_*yer 3 javascript node.js

我用一段代码运行 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/');
Run Code Online (Sandbox Code Playgroud)

我用gitbash运行它给它的欲望输出.但是使用node js命令提示它给出了microsoft jscript编译错误.

Mok*_*oki 9

看起来你只是在终端窗口中输入了脚本的名称,因此要求windows为你的脚本找到合适的解释器.您应该尝试使用nodejs解释脚本:

node your-script.js
Run Code Online (Sandbox Code Playgroud)

不只是

your-script.js
Run Code Online (Sandbox Code Playgroud)


Gre*_*isz 2

这里的问题可能源于几个地方。最有可能的是基于安装的。

以下代码(取自上面)

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/');
Run Code Online (Sandbox Code Playgroud)

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

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

1.1 如果使用除纯文本编辑器之外的任何编辑器(notepad++、notepad、sublime 等),请确保文件实际上设置为输出纯文本(骨子里移动但经常被忽视)

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

  2. 如果所有其他方法都失败并且您已安装 npm,请输入“npm install http”并重新运行您的first.js 应用程序