2016-01-20 35 views
1

我很新的NodeJS 当我试图运行我的第一个js文件中有如下内容语法错误

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/'); 

用命令

$节点FULLPATH/filename.js

抛出类似下面 error message

谁能告诉什么是错

我收到错误。我使用的NodeJS机应用窗口

+2

我没有得到任何错误运行它,如果我跑相同代码,你有任何其他代码js – saikumar

+1

检查你的HTTP库..如果它安装正确 – madhairsilence

回答

6

请不要运行在REPL

[[email protected]]$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) 

的代码只需在命令行

[[email protected]]$node app.js 
Server running at http://127.0.0.1:8081/ 
+0

我得到它。我有两个nodejs命令行,其中node.js命令提示符正在工作,但nodejs窗口仍然创建错误 – JithPS