balderdashy / waterline-docs

WARNING: The content in this repo is out of date! See https://github.com/balderdashy/sails-docs for the most up-to-date documentation
452 stars 161 forks source link

Express example without modifying the app object #90

Closed reecefenwick closed 9 years ago

reecefenwick commented 9 years ago

Hi I am looking to implement waterline and struggling to find the most efficient way of implementing this with my express application.

I want to avoid modifying the app or req objects as:

  1. My controllers don't have access to the app object
  2. Introduces tight coupling between modules

I currently manage my database connection like so with mongoose:

var mongoose = require('mongoose');

mongoose.connect(config.get('dbURI'));

mongoose.connection.on('error', function (err) {
    logger.error('database connection error', arguments);
});

mongoose.connection.on('open', function () {
    logger.log('Connected to the database');
});

Then in any of my controllers I simply just require my mongoose models.

Is there a way I can take a similar approach?

Or am I forced to initialize before I start listening for requests since the initialize step is asynchronous?