1.0.0 • Published 7 years ago

express-insert-mw v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Express Insert Middleware

Call express middlewares just before calling next or sending response

Installation

$ npm install express-insert-middleware

Usage

Use this module to manualy call middleware inside your express

For example,

var insertMiddleware = require('express-insert-mw');

/* Init your express app */

/* Create a basic middleware */
function loadProfileInfo(req, res, next) {
    /* Load informations from BDD { */
        req.user = {
            name: nameFromBDD
        };
        next();
    /* } */
}
app.use(loadProfileInfo);

/* Basic profile page */
app.get('/profile',
    function(req, res) {
        res.send('Hello ' + req.user.name);
    }
);

/* Edit profile request */
app.post('/profile',
    function(req, res) {

        /* Set new profile information in BDD { */

            /* Then reload profile informations with the middleware */
            insertMiddleware(req, res, [loadProfileInfo], function(req, res) {
                res.send('Hello ' + req.user.name);
            });

        /* } */

    }
);

You can pass an array of multiple middlewares

License

This project is licensed under the MIT license.