mongodb-launcher
A simple process launcher for creating test instance of mongodb to use in
testing. Usually the reason you'll want to do this is to make sure your test
databases are isolated from your default mongo instance so tests cannot destroy
real data. It also allows you to run your tests without assuming processes
outside the test runner are already running.
Starting a mongo instance
You can start as many mongo instances as you need by passing different ports. If an instance is already running on that port, the start function will call
back immediately.
var mongo = require('mongodb-launcher');
var args = {port:45000, dbPath: './testDb'};
var db;
mongo.start(function(err, _db) {
if (err) {
console.error(err);
process.exit(1);
}
db = _db;
console.log('Mongo instance alive on port', args.port);
});
Stopping a mongo instance
To stop a mongo instance, you can either call the stop method on the returned
db intance, or call stop on the module, passing in the port of the instance you
want to kill.
db.stop(function(err) {
// ...
});
// OR
mongo.stop(45000, function(err) {
// ...
});
Emitted events