Socket
Socket
Sign inDemoInstall

request-stats

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    request-stats

Get stats on your Node.js HTTP server requests


Version published
Maintainers
1
Install size
14.5 kB
Created

Readme

Source

request-stats

Build Status

Get stats on your Node.js HTTP server requests.

Emits an stats event for each request with a single object as its first argument, containing the following properties:

  • ok: true if the connection was closed correctly and false otherwise
  • time: The milliseconds it took to serve the request
  • req:
    • bytes: Number of bytes sent by the client
    • headers: The headers sent by the client
    • method: The HTTP method used by the client
    • path: The path part of the request URL
  • res:
    • bytes: Number of bytes sent back to the client
    • headers: The headers sent back to the client
    • status: The HTTP status code returned to the client

Installation

npm install request-stats

Usage

var requestStats = require('request-stats');

http.createServer(function (req, res) {
  requestStats(req, res).on('stats', function (stats) {
    console.log(stats); // { read: 42, written: 123, method: 'PUT', status: 200 }
  });
});

Or you can just parse it the http.Server object to a completely decoupled experience:

var server = http.createServer(function (req, res) {
  // ...
});

requestStats(server).on('stats', function (stats) {
  console.log(stats); // { read: 42, written: 123, method: 'PUT', status: 200 }
});

Can also be used as Connect/Express middleware:

app.use(requestStats.middleware());

requestStats().on('stats', function (stats) {
  console.log(stats); // { read: 42, written: 123, method: 'PUT', status: 200 }
});

Acknowledgement

Thanks to mafintosh for coming up with the initial concept and pointing me in the right direction.

License

MIT

Keywords

FAQs

Last updated on 10 Jun 2014

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc