model-binder

1.0.1 • Public • Published

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);
});

Readme

Keywords

none

Package Sidebar

Install

npm i model-binder

Weekly Downloads

2

Version

1.0.1

License

ISC

Last publish

Collaborators

  • dselmanovic