这真的很基础......我刚刚开始使用 Node.js。
我有一个简单的模块
服务器.js
var http = require("http");
function start() {
function onRequest() {
console.log("Request received");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started...");
}
export.start = start;
它是从 index.js 中调用的,如下所示
var server = require("./server");
server.start();
但是跑步node index.js
给了我这个!
$ node index.js
d:\SourceRepo\node-sample\server.js:15
export.start = start;
^^^^^^
SyntaxError: Unexpected reserved word
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (d:\SourceRepo\node-sample\index.js:1:76)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
如何解决这个问题?我是 JavaScript 的新手!