This is really fundamental... I am just getting started with Node.js.
I have a simple module
server.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;
and it's being called from index.js as follows
var server = require("./server");
server.start();
but running node index.js
gives me this!
$ node index.js
d:\SourceRepo\node-sample\server.js:15
export.start = start;
^^^^^^
SyntaxError: Unexpected reserved word
at Module._pile (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._pile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
How to sort this out? I am a newbie to JavaScript!
This is really fundamental... I am just getting started with Node.js.
I have a simple module
server.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;
and it's being called from index.js as follows
var server = require("./server");
server.start();
but running node index.js
gives me this!
$ node index.js
d:\SourceRepo\node-sample\server.js:15
export.start = start;
^^^^^^
SyntaxError: Unexpected reserved word
at Module._pile (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._pile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
How to sort this out? I am a newbie to JavaScript!
Share Improve this question asked Dec 21, 2012 at 17:20 saratsarat 11.2k7 gold badges48 silver badges76 bronze badges 1- 1 export is in fact a reserved word in javascript – Aaron Kurtzhals Commented Dec 21, 2012 at 17:24
1 Answer
Reset to default 13You need to use exports
, with an "s".