http-responders
Zero-dependency HTTP response functions.
Supports:
status
json
redirect
stream
file
download
Example
import { status, json, redirect, stream, file, download } from 'http-responders'
http.createServer(async (req, res) => {
status(res, 404)
json(res, { beep: 'boop' })
redirect(req, res, 'https://example.com/')
await stream(res, fs.createReadStream('file.txt'))
await file(res, 'file.txt')
await download(res, 'file.txt)
})
Installation
$ npm install http-responders
API
.status(res, code)
.json(res, json)
.redirect(req, res, location[, code = 302])
await .stream(res, stream)
await .file(res, path, [fsOpts])
await .download(res, path, [fsOpts])
License
MIT