最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting Microsoft JScript compilation error - Stack Overflow

programmeradmin2浏览0评论

I run a piece of code with 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/');

while i m running it with gitbash its giving desire output. but with node js command prompt its giving microsoft jscript compilation error.

I run a piece of code with 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/');

while i m running it with gitbash its giving desire output. but with node js command prompt its giving microsoft jscript compilation error.

Share Improve this question edited Apr 11, 2016 at 6:15 Priya 1,3556 gold badges21 silver badges41 bronze badges asked Apr 11, 2016 at 5:37 PrayerPrayer 831 gold badge1 silver badge5 bronze badges 1
  • 1 node.js has nothing to do with JScript so you are running your script using a wrong interpreter. – Anatol - user3173842 Commented Apr 11, 2016 at 6:18
Add a comment  | 

4 Answers 4

Reset to default 21

Looks like you've just typed script's name into the terminal window therefore asked windows to find proper interpreter for your script. You should try and interpret the script with nodejs instead:

node your-script.js

not just

your-script.js

The issue here could stem from several places. Most likely installation-based.

The following code (Taken from above)

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/');

Yields positive results when I attempt to load it in the browser. I therefore recommend the following:

  1. Try run what I put into the code snippet window into a brand new first.js file in a brand new directory and from command line navigate to the directory and run the file with the command "Node first.js" (Without quotes naturally).

1.1 If using any editor aside from a plain text editor (notepad++, notepad, sublime etc) ensure the file is in-fact set to output plain-text (bone-head move but often overlooked)

  1. Reinstall node (Worth a shot)

  2. If all else fails and you have npm installed, type "npm install http" and re-run your first.js application

I was getting the same error repeatedly on my nodejs app and then realized I wrote only "index.js"(the script file name on the package.json file). So whenever I ran the command npm start it was giving me that error. I had nodemon installed on my app so I changed it to nodemon index.js after that it worked perfectly. I am attaching the screenshot here:

What helped me is - I removed --exec after nodemon command in my script section of package.json file.

Previously it was -

"dev": "nodemon --exec src/index.js"

I changed it to -

"dev": "nodemon src/index.js"

NOTE: my index file is inside src directory.

发布评论

评论列表(0)

  1. 暂无评论