我对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/');
使用命令
$ node fullpath / filename.js
任何人都可以说出错了什么。我正在使用nodejs应用窗口
答案 0 :(得分:6)
请不要在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)
只需在命令行中运行
即可[user@machine]$node app.js
Server running at http://127.0.0.1:8081/