3

I am very newbie to node.js. In the node REPL everything was working fine. But something changed. When I try to execute a 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 this...

node --version

I have the following code in the 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 to only console.log something, or just leave the file blank it's the same issue.. enter image description here

1
  • What's inside your module.js file? Commented Mar 24, 2015 at 15:13

2 Answers 2

3

You can't call the node executable from within the node REPL... Only JavaScript statements/expressions.

Try require('./module.js')

Sign up to request clarification or add additional context in comments.

4 Comments

Actually I am using Git Bash to execute node scripts. Does that matter? It was working just fine few days back!
You probably didn't enter the node REPL then. There's no reason it would work inside the REPL...
Ok, how do I do it then? How do I execute it from Git bash? I did a manual delete of few npm modules.
Without executing node, just execute node module.js
1

Are you running node by double clicking on it?

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

node should be in your class path or while executing node use full path. such as c:\work\nodetest\node .\xyz.js

in above i coped the js file in same folder as node file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.