Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 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.

like image 840
Prayer Avatar asked Apr 11 '16 05:04

Prayer


2 Answers

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
like image 125
MarengoHue Avatar answered Sep 28 '22 16:09

MarengoHue


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

like image 24
Greg Rebisz Avatar answered Sep 28 '22 18:09

Greg Rebisz