Response Time
Connect middleware to calculate response times.
Similar to response-time, except this implementation does not set a response header for the calculated time and does not override the default response.writeHead
method.
The calculated response time is output to a callback
provided on initialization. Accordingly, the module is better suited for logging response times and monitoring application performance.
Installation
$ npm install connect-middleware-response-time
Usage
To use the module,
var responseTime = ;
responseTime( clbk )
The middleware generator accepts a callback
which should accept a numeric
value as its only input.
var mw = ;{console;}
Notes
In the event that an HTTP response terminates prematurely, the returned response time is NaN
.
Examples
var express =request =responseTime = ;// Define a port:var PORT = 7331;// Create a new application:var app = ;// Use the response time middleware for all requests:app;// Bind a route:app;// Spin up a new server:var server = app;{;}{if errorthrow error ;console;}{var rand = Mathidx = 0x;for var i = 0; i < rand; i++x = Math;;}{console;}{responsestatus 200;}
To run an example from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2014. Athan Reines.