Skip to content

Instantly share code, notes, and snippets.

@VivienAdnot
Created July 30, 2018 12:02
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 VivienAdnot/d5ddb1bed7f124721052fc75d2c03c59 to your computer and use it in GitHub Desktop.
Save VivienAdnot/d5ddb1bed7f124721052fc75d2c03c59 to your computer and use it in GitHub Desktop.
busboy case 1: write file to disk
var http = require('http');
var fs = require('fs');
var Busboy = require('busboy');
http.createServer(function(req, res) {
var busboy = new Busboy({
headers: req.headers
});
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
var saveTo = 'uploaded.txt';
file.pipe(fs.createWriteStream(saveTo));
});
busboy.on('finish', function() {
res.writeHead(200, {
'Connection': 'close'
});
res.end("That's all folks!");
});
return req.pipe(busboy);
}).listen(8001, function() {
console.log('server3 is listening for requests on 8001');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment