Search code examples
javascriptnode.jsrequest-headersnode.js-streambusboy

node.js - How does Busboy actually work?


I'm a bit confused with Busboy module. I don't understand where it takes file data to stream as it accepts only request headers as parameter?! Take a look on example from docs:

var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
   //...
   // btw file is ReadableStream!
});

Solution

  • It gets the request body piped to it, see the example:

    req.pipe(busboy);