Node REPL throws SyntaxError: Unexpected identifier

I am very new to node.js. In node REPL, everything worked fine. But something has changed. When I try to execute the file, it shows this ...

D:\Projects-2015\uniqueva>node />node module.js SyntaxError: Unexpected identifier at Object.exports.createScript (vm.js:44:10) at REPLServer.defaultEval (repl.js:117:23) at bound (domain.js:254:14) at REPLServer.runBound [as eval] (domain.js:267:12) at REPLServer.<anonymous> (repl.js:279:12) at REPLServer.emit (events.js:107:17) at REPLServer.Interface._onLine (readline.js:214:10) at REPLServer.Interface._line (readline.js:553:8) at REPLServer.Interface._ttyWrite (readline.js:830:14) at ReadStream.onkeypress (readline.js:109:10) 

It happens even when I try it ...

 node --version 

I have the following code in module.js ..

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

.. but even if I try only console.log something, or just leave the file empty, this is the same problem .. enter image description here

+3
source share
2 answers

You cannot invoke the node executable from node REPL ... Only JavaScript statements / expressions.

Try require('./module.js')

+3
source

Are you using node by double clicking on it?

You need to run node from the command line and give the node xyz.js command on the command line.

node must be in your class path or use node full path when executing node. e.g. c: \ work \ nodetest \ node. \ xyz.js

in the above, I dealt with the js file in the same folder as the node file.

+1
source

Source: https://habr.com/ru/post/1236873/


All Articles