mongodb-instance

Installs mongodb locally

mongodb-instance

Downloads and installs mongodb relative to the package, intended for testing purposes.

npm install mongodb-instance

'use strict';
 
var mongod = require('mongodb-instance'),
    path   = require('path'),
    MongoClient = require('mongodb').MongoClient;
 
var port = 27000;
var instance = mongod.start({
  port: port,
  dbpath: path.join(__dirname, 'db')
});
 
setTimeout(function () {
  MongoClient.connect('mongodb://localhost:' + port, function (errdb) {
    if (err) {
      console.error(err);
    } else {
      console.log('Connected to db: ' + db.databaseName);
      db.close();
    }
    
    setTimeout(instance.stop.bind(instance), 1000);
  });
}, 1000);
  • Only tested on a mac
  • Suffers from racing conditions when starting up (use setTimeout for now)
  • Do not install globally (-g)