Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created August 7, 2012 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heapwolf/3282137 to your computer and use it in GitHub Desktop.
Save heapwolf/3282137 to your computer and use it in GitHub Desktop.
http/pipe-req
var fs = require('fs');
require('http').createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
if (req.method === 'GET') {
fs.createReadStream(__dirname + '/form.html').pipe(res);
} else {
var fileName = __dirname + '/request_' + Date.now() + '.log';
console.log('writing to ', fileName);
var file = fs.createWriteStream(fileName);
req.pipe(file);
req.on('end', function() {
res.end('Submitted, thanks');
});
}
}).listen(4001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment