A small and simple Mongoose model loader/initiator
npm install mongoload
index.js:
var mongoload = require('mongoload'),
mongoose = require('mongoose');
// connect mongoose as usual...
mongoload.bind(mongoose).load({pattern: __dirname + '/models/*.js'});
./models/MyModel.js:
module.exports = function (mongoose, modelName) {
// Define your mongoose model as usual...
var schema = mongoose.Schema({
name: String
});
// `modelName` in here will be "MyModel"
mongoose.model(modelName, schema);
};
MIT