Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var express = require('express')
, cors = require('cors')
, app = express();
var fs = require('fs');
app.use(cors());'/post', function(req, res, next){
var body = [];
req.on('data', function(chunk) {
}).on('end', function() {
body = Buffer.concat(body).toString();
var parsedData = JSON.parse(body);
var filename = parsedData['q'].replace(' ','_').replace(/\./g,'').replace(/\\/g,'');
var filepath = "/tmp/"+filename+'.txt';
fs.writeFile(filepath, body, function(err) {
if(err) {
return console.log(err);
console.log("The file "+filepath+" was saved!");
res.json({msg: 'This is CORS-enabled for all origins!'});
app.listen(8000, function(){
console.log('CORS-enabled web server listening on port 80');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment