Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Created January 22, 2013 14:38
Show Gist options
  • Save nickleefly/4595102 to your computer and use it in GitHub Desktop.
Save nickleefly/4595102 to your computer and use it in GitHub Desktop.
curl -X POST -d "im doing testing" http://localhost:8080 createServer using writeStream and readStream
var http = require('http');
var fs = require('fs');
function randomFileName() {
return '/' + Date.now() + '_' + Math.random() * 1000000 + '.txt';
}
http.createServer(function(req, res) {
var fileName = randomFileName();
console.log('writing request to', fileName);
req.pipe(fs.createWriteStream(fileName));
res.writeHead(200, {'content-type': 'text/plain'});
fs.createReadStream(__filename).pipe(res);
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment