Skip to content

Instantly share code, notes, and snippets.

@heapwolf heapwolf/43.js
Created Aug 7, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.