Created
August 7, 2012 05:56
-
-
Save heapwolf/3282137 to your computer and use it in GitHub Desktop.
http/pipe-req
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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