1.0.1 • Published 7 years ago

model-binder v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

ModelBinderJS

NodeJS/ExpressJS middleware module for automated binding of request parameters to specified Model function

Usage

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

function Person(){
    this.name='default name';
    this.email='default email';
    this.sayName=function(){
        console.log(this.name);
    };
}

module.exports=Person;

Then in your app just register binder middleware on actions where you need it:

var binder=require('model-binder');

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