https://github.com/dimitrinicolas/express-insert-mw
Call express middlewares just before calling next() or sending a response
https://github.com/dimitrinicolas/express-insert-mw
express middleware nodejs
Last synced: 3 months ago
JSON representation
Call express middlewares just before calling next() or sending a response
- Host: GitHub
- URL: https://github.com/dimitrinicolas/express-insert-mw
- Owner: dimitrinicolas
- License: mit
- Created: 2017-10-14T10:17:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-10T16:11:39.000Z (over 8 years ago)
- Last Synced: 2025-09-06T09:56:19.969Z (10 months ago)
- Topics: express, middleware, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/express-insert-mw
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Express Insert Middleware
Call express middlewares just before calling next or sending response
## Installation
```sh
$ npm i express-insert-mw
```
## Usage
Use this module to manually call middleware inside your express
For example,
```js
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](LICENSE).