Socket
Book a DemoInstallSign in
Socket

http-responders

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-responders

Zero-dependency http responders

latest
Source
npmnpm
Version
2.2.0
Version published
Maintainers
0
Created
Source

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) => {

  // 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)

})

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

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts