then-busboy
Promise-based wrapper around Busboy, inspired by async-busboy
Installation
Use can install then-pusboy
from npm:
npm install theb-busboy --save
Or with yarn
yarn add then-busboy
yarn
Usage
Just import then-busboy
and pass request
object as first argument.
For example:
var busboy = require("then-busboy");
var createServer = require("http").createServer;
function callback(req, res) {
if (req.method === "GET") {
res.statusCode = 404
return res.end("Not Found");
}
if (req.method !== "POST") {
res.statusCode = 405;
return res.end("Method Not Allowed");
}
function onFulfilled(data) {
res.writeHead("Content-Type", "application/json");
res.end(JSON.stringify(data));
}
function onRejected(err) {
res.statusCode = err.status || 500;
res.end(String(err));
}
busboy(req).then(onFulfilled, onRejected);
}
createServer(callback)
.listen(2319, () => console.log("Server started on http://localhost:2319"))
then-busboy
always return a Promise, so you can use it with
asynchronous function syntax:
await = busboy(req);
License
MIT