0.1.0 • Published 7 years ago
mongobox v0.1.0
mongobox.js
Start and stop a sandboxed instance of MongoDB from within a node.js application. Extremely useful for unit tests and no mocks of database required. The sandboxed MongoDB instance will run on a free port alongside other instances and will create files in a temporary directory that will be removed after the process exits.
var MongoBox = require('mongobox').MongoBox;
var options = {};
var mongobox = new MongoBox(options);
mongobox.start(function(err) {
if (err) return console.error('Could not start the database: %s', err);
mongobox.stop(function(err, code) {
if (err) return console.error('Could not stop: %s',err);
console.log('Stopped with code %s', code);
});
});Constructor options are:
databasePath- temporary path for the database files. Will be created if it does not exist. By default a random temporary directory will be created.mongodBinary- location of themongodbinary. By default the one from systemPATHis used.port- port to use. By default a random free port will be chosen.auth-mongod's--authcommand line value.scripting- removesmongod's--noscriptingenabled by default.prealloc- removesmongod's--nopreallocenabled by default.
var mongobox = new MongoBox({port:1337, databasePath: '/tmp/foobar'});