then-busboy
Promise-based wrapper around Busboy, inspired by async-busboy
![Code Coverage](https://codecov.io/github/octet-stream/then-busboy/coverage.svg?branch=master)
Installation
Use can install then-busboy
from npm:
npm install --save then-busboy
Or with yarn
yarn add then-busboy
Usage
busboy(request[, options]) -> Promise
- http.IncomingMessage request – HTTP request object
- object options
- boolean restoreTypes – allow to restore type of each value (default – true)
- more information about busboy options here.
Just import then-busboy
and pass request
object as first argument.
For example:
const busboy = require("then-busboy")
const createServer = require("http").createServer
function handler(req, res) {
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(handler)
.listen(2319, () => console.log("Server started on http://localhost:2319"))
then-busboy
always returns a Promise, so you can use it with
asynchronous function syntax:
const data = await busboy(req)
License
MIT