Zero-dependency HTTP response functions.
Supports:
status
json
redirect
stream
file
download
import { status, json, redirect, stream, file, download } from 'http-responders'
http.createServer(async (req, res) => {
// Respond with HTTP Status
status(res, 404)
// Respond with JSON
json(res, { beep: 'boop' })
// Redirect
redirect(req, res, 'https://example.com/')
// Respond with a generic stream
await stream(res, fs.createReadStream('file.txt'))
// Respond with a file (+ content length)
await file(res, 'file.txt')
// Make the browser download the file
await download(res, 'file.txt)
})
$ npm install http-responders
MIT