Neovictorian Paisley Menswear
    Wondering what’s next for npm?Check out our public roadmap! »

    on-http-end

    1.0.2 • Public • Published

    on-http-end

    Allows to capture HTTP response content and headers on request end.

    Inspired by: https://github.com/kwhitley/apicache/blob/master/src/apicache.js

    Install

    npm i on-http-end

    Usage

    const onEnd = require('on-http-end')
    const http = require('http')
     
    const server = http.createServer((req, res) => {
      onEnd(res, (payload) => {
        console.log(payload)
      })
     
      res.setHeader('my-header', 'value')
      res.end('Hello Word!', 'utf-8')
    })
     
    server.listen(3000)

    Output:

    {
      status: 200,
      headers: [Object: null prototype] { 'my-header''value' },
      data: 'Hello Word!',
      encoding: 'utf-8'
    }

    Want to contribute?

    This is your repo ;)

    Note: We aim to be 100% code coverage, please consider it on your pull requests.

    Install

    npm i on-http-end

    DownloadsWeekly Downloads

    1,035

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    5.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar