Skip to content
Zero-dependency http responders
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
.gitignore
.prettierignore
LICENSE
README.md
index.js
package-lock.json
package.json
test.js

README.md

http-responders

Zero-dependency HTTP response functions.

Supports:

  • json
  • redirect
  • stream
  • file
  • download

Example

const { json, redirect, stream, file, download } = require('http-responders')

http.createServer((req, res) => {

  // Respond with JSON
  json(res, { beep: 'boop' })

  // Redirect
  redirect(req, res, 'https://example.com/')

  // Respond with a generic stream
  stream(res, fs.createReadStream('file.txt'))

  // Respond with a file (+ content length)
  file(res, 'file.txt')

  // Make the browser download the file
  download(res, 'file.txt)

})

Installation

$ npm install http-responders

API

.json(res, json)

.redirect(req, res, location)

await .stream(res, stream)

await .file(res, path, [fsOpts])

await .download(res, path, [fsOpts])

Sponsors

Development of this module is sponsored by:

Liberate Science

License

MIT

You can’t perform that action at this time.