1

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

2
  • 2
    I am not getting any error, if i run same code, do you have any other code in js Commented Jan 20, 2016 at 9:02
  • 1
    check ur http library.. if it is installed properly Commented Jan 20, 2016 at 9:07

1 Answer 1

6

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/
Sign up to request clarification or add additional context in comments.

1 Comment

i got it.i had two nodejs commandlines where the node.js command prompt is working but nodejs window still creates the error

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.