mfuhrmeister / nodejs-embedded-mongodb-standalone

Embedded mongodb library that downloads a appropriate mongodb and utilizes it as standalone.
MIT License
5 stars 4 forks source link

nems

npm license github-issues

nodejs-embedded-mongodb-standalone is a promise based embedded mongodb distribution library that downloads a appropriate mongodb and utilizes it as standalone, e.g. for integration/functional tests.

nodei.co

stars forks

CircleCI: Circle CI build status

Features

Distributer

Downloads and extracts mongodb for a given version and download directory. The version is mandatory, the download directory may default to the OS temporary directory.

Usage:
var nems = require('nems');

nems.distribute('3.2.8', '.')
    .then(function (path) {
      // do anything else with the 'path' to the extracted mongo directory
    }).catch(function(err) {
      // catch any DownloadError, ExtractionError or standard Error
    });

You can use the download and extraction service separately:

Usage:
var nems = require('nems');

nems.download('3.2.8', '.')
    .then(function (file) {
      // do anything else with the 'file' string
    }.catch(err) {
      // catch any DownloadError or standard Error
    };

nems.extract('/path/to/file.gz', '3.2.8', '.')
    .then(function (path) {
      // do anything else with the 'path' to the extracted mongo directory
    }.catch(err) {
      // catch any ExtractionError or standard Error
    };

Process

Start a mongodb for the given file path.

Usage:
var nems = require('nems');

/**
 * Parameter: 
 *  path - path to the mongodb installation
 *  port - the mongodb port (optional)
 *  noprealloc - do not pre-allocate (optional)
 *  nojournal - do not use a journal (optional)
 *  dbpath - db working directory, if different from installation path (optional)
 * 
 */
nems.startMongo('path/to/mongodb/installation', 27017, true, true, 'path/to/db/working/directory')
    .then(function (pid) {
      // do anything with the returned process id
    }.catch(err) {
      // catch any standard Error, e.g. if child process to start mongo crashed
    };

Interface

A sophisticated module interface to download, extract and start a mongodb at once, as well as stopping it.

Usage:
var nems = require('nems');

/**
 * Parameter: 
 *  version - the desired mongodb version
 *  downloadDir - the directory to download and extract to (optional, defaults to the OS temporary directory)
 *  port - the mongodb port (optional)
 *  noprealloc - do not pre-allocate (optional)
 *  nojournal - do not use a journal (optional)
 *  dbpath - db working directory, if different from installation path (optional)
 * 
 */
nems.start('3.2.8', '.', 27017, true, true, 'path/to/db/working/directory')
    .then(function (pid) {
      // do anything with the returned process id
    }.catch(err) {
      // catch any MongoError or standard Error, e.g. if child process to start mongo crashed
    };

/**
 * Parameter: 
 *  path - path to the mongodb installation
 *  dbpath - db working directory, if different from installation path (optional)
 */
nems.stop('path/to/mongodb/installation','path/to/db/working/directory')
    .then(function (successMessage) {
      // do anything after mongodb shutdown
    }.catch(err) {
      // catch any MongoError or standard Error, e.g. if child process to start mongo crashed
    };

Install

npm i -S nems

Scripts

Within this module use:

Within the source code project:

Contributing

Contributions welcome! Please submit all pull requests against master branch. If your pull request contains JavaScript patches or features, you should fully cover the code with unit tests. Thanks!

Author

Marcus Fuhrmeister marcus.fuhrmeister@googlemail.com https://github.com/mfuhrmeister

License