Skip to content

Instantly share code, notes, and snippets.

@rhengles rhengles/index.js
Last active Aug 29, 2015

Embed
What would you like to do?
Node server that save POSTs to a file
var http = require('http')
, fs = require('fs');
var save = fs.createWriteStream('save.txt')
, server = http.createServer(function(req, resp) {
resp.setHeader('Access-Control-Allow-Origin', '*');
var url = req.url;
console.log(url);
if ( '/exit' === url ) {
resp.end('BYE');
server.close();
save.end();
} else if ( '/save' === url ) {
if ( 'POST' === req.method ) {
req.pipe(save);
resp.end('SAVED');
} else {
resp.end('SAVE IS NOT POST');
}
} else {
resp.end('WHATEVER');
}
});
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.