Skip to content

Instantly share code, notes, and snippets.

@loopDelicious
Created August 28, 2017 19:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save loopDelicious/213881bc1d4c8f64e1404aa7c7cbb413 to your computer and use it in GitHub Desktop.
Save loopDelicious/213881bc1d4c8f64e1404aa7c7cbb413 to your computer and use it in GitHub Desktop.
Example of writing to a local file
var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json()); // Body parser use JSON data
app.post('/launches', function(req, res) {
var outputFilename = './spaceReport.json'; // path of the file to output
fs.writeFileSync(outputFilename, JSON.stringify(JSON.parse(req.body.payload), null, 4)); // write to the file system
res.send('Saved to ' + outputFilename);
});
var port = 3000;
app.listen(port);
console.log('Express started on port %d ...', port);
@loopDelicious
Copy link
Author

If receiving this error: “PayloadTooLargeError: request entity too large”

maybe try:

app.use(bodyParser.json({limit: ’50mb’, extended: true}))
app.use(bodyParser.urlencoded({limit: ’50mb’, extended: true}))

@davidcsaint
Copy link

Thank you!

@makifyegin
Copy link

That's fine it works. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment