New to node.js.
I'm setting up integration tests for a node.js app with mocha, following this guide: http://taylor.fausak.me/2013/02/17/testing-a-node-js-http-server-with-mocha/
Created a server as follows:
var http = require('http');
this.server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, world!\n');
});
exports.listen = function () {
this.server.listen.apply(this.server, arguments);
};
exports.close = function (callback) {
this.server.close(callback);
};
The listen and close functions are so that:
- require('server') is idempotent
- server can be started and stopped in tests
Question:
How can I create a launch script that calls server.listen on startup? Currently it is launched with with:
"scripts": {
"test": "mocha --reporter spec",
"start": "nodemon server.js"
}
^-- I want to add an invocation of server.listen() to the script above.