JithPS
JithPS

Reputation: 1217

Syntax error in nodeJs file run

i am very new to nodejs when i tried to run my first js file having following content

var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8081);
console.log('Server running at http://127.0.0.1:8081/');

with the command

$ node fullpath/filename.js

i am getting error thrown like below error message

Can anyone tell what is wrong. I am using nodejs appliction window

Upvotes: 1

Views: 943

Answers (1)

zangw
zangw

Reputation: 48536

Please do not run the code in the REPL

[user@machine]$node
> node app.js
SyntaxError: Unexpected identifier
    at Object.exports.createScript (vm.js:24:10)
    at REPLServer.defaultEval (repl.js:225:25)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)

Just run it in the command line

[user@machine]$node app.js
Server running at http://127.0.0.1:8081/

Upvotes: 6

Related Questions