Last active
August 29, 2015 14:20
-
-
Save daffl/760e744add03b7ae6303 to your computer and use it in GitHub Desktop.
An Epress middleware example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var bodyParser = require('body-parser'); | |
| var app = express(); | |
| app.use(bodyParser.json()) | |
| .use(function(req, res, next) { | |
| // Add the username to the parsed body | |
| // set by bodyParser middleware | |
| req.body.username = 'David'; | |
| next(); | |
| }) | |
| .use(function(req, res) { | |
| res.json(req.body || { message: 'No content' }); | |
| }); | |
| app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment