modreal-mongoose-connection

0.0.3 • Public • Published

modreal-mongoose-connection

This is an opinionated simple mongoose connection package. It assumes:

  • you're using modreal/config and have a config/mongo.json with db urls
  • you're using modreal/logger for logging with loggly

It handles closing the connection when the script is killed, and giving error messages when it can't connect.

How To Use

Create a config/mongo.json file, and add to it something like:

{
  "development": "mongodb://localhost:27017/dev_db",
  "test": "mongodb://localhost:27017/test_db"
}

Then install mongoose-connection:

$ npm install modreal/mongoose-connection --save

Require it, and add your callback to the connection:

// javascript

var connection = require("modreal-mongoose-connection");
connection.on("connected", function() {
  // start app
});
# coffeescript

connection = require 'modreal-mongoose-connection'
connection.on 'connected', ->
  # start app

The package checks for a global mongoose library as well.

global.mongoose = require('mongoose')

// later

connection.mongoose == global.mongoose

License

MIT


AJ Ostrow, November 2013

Readme

Keywords

none

Package Sidebar

Install

npm i modreal-mongoose-connection

Weekly Downloads

3

Version

0.0.3

License

none

Last publish

Collaborators

  • aj0strow