Skip to content

Instantly share code, notes, and snippets.

@wprudencio
Created July 10, 2017 19:35
Show Gist options
  • Save wprudencio/91d0a578d4cd32e02644ee699b98f36e to your computer and use it in GitHub Desktop.
Save wprudencio/91d0a578d4cd32e02644ee699b98f36e to your computer and use it in GitHub Desktop.
Check the body of a post request and save in a file
var express = require('express');
var app = express();
var bodyParser = require('body-parser')
var fs = require('fs');
// to support JSON-encoded bodies
// app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
// extended: true
// }));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.post('/', function (req, res) {
console.log(req.headers);
console.log(req.body);
fs.writeFile(Date(), JSON.stringify(req.body), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
res.send('Hello World!');
});
app.listen(8080, function () {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment