Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created December 7, 2013 00:58
Show Gist options
  • Save seansullivan/7835884 to your computer and use it in GitHub Desktop.
Save seansullivan/7835884 to your computer and use it in GitHub Desktop.
node.js middleware to write raw request body to log file.
var fs = require('fs');
app.use(function(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function() {
fs.writeFile('request-body.log', req.rawBody, function (err) {
console.log(err);
});
next();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment