0.0.1-3 • Published 9 years ago

mongoose-model-binder v0.0.1-3

Weekly downloads
-
License
ISC
Repository
github
Last release
9 years ago

MongooseModelBinder

ExpressJS middleware module for automated mongoose model binding of request parameters

Requirements

You need body-parser and mongoose modules.

npm install body-parser --save
npm install mongoose --save

Usage

Create your schema in separate JS file (ex. person.js):

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var UserSchema = new Schema({
    username: { type: String, required: true, unique: true },
	password: { type: String, required: true }
});

module.exports = UserSchema;

Then in your app just register binder middleware on actions where you need it indicating your schema file and the instance name you want. You must include body-parser in your request or globally:

var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
var binder = require('mongoose-model-binder');

app.get('/testmodel', binder(require('./person', 'person')), function(req, res){
    console.log(req.person);
    return res.send(req.person);
});

Module based on https://github.com/dselmanovic/model-binder

0.0.1-3

9 years ago

0.0.1-2

9 years ago

0.0.1-1

9 years ago

0.0.1

9 years ago