npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@luminati-io/express-latency

v0.0.4-lum.0

Published

Profile route and middleware latency for express.js apps.

Downloads

189

Readme

express-latency

express-latency is an express.js module that allows you to profile the latency in your app's requests, or how long each (global/route) middleware and controller take to execute. It can help you solve sluggishness problems in your app and give you an idea of how long your requests take server-side.

This is an alpha release.

Installation

$ npm install express-latency

Usage:

Enable express-latency by adding the following middleware after your app's routes have been declared:

var express = require('express');
var latency = require('express-latency');

// create express app here 
var app = express.createServer();

// something, something

// enable middleware
app.use(express.logger());
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.static(public_directory), {maxAge: 86400000});
app.use(app.router);

// add your routes
app.get('/', function (req, res) {
  res.send('Measure me!');
});

// add it right after all your route definitions
latency.measure(app, {print: true});

express-latency builds the latency object for the request file. Use

req.latency

to access it. req.latency is structured like the following:

[{"info":{"type":"global-middleware","index":0,"name":""},"done":1320012478268,"duration":0},{"info":{"type":"global-middleware","index":1,"name":"logger"},"done":1320012478268,"duration":0},{"info":{"type":"global-middleware","index":2,"name":"methodOverride"},"done":1320012478268,"duration":0},{"info":{"type":"global-middleware","index":3,"name":"bodyParser"},"done":1320012478268,"duration":0},{"info":{"type":"global-middleware","index":4,"name":"cookieParser"},"done":1320012478269,"duration":1},{"info":{"type":"global-middleware","index":5,"name":"session"},"done":1320012478271,"duration":2},{"info":{"type":"global-middleware","index":6,"name":"processUserAgent"},"done":1320012478272,"duration":1},{"info":{"type":"global-middleware","index":7,"name":"renderArgs"},"done":1320012478272,"duration":0},{"info":{"type":"global-middleware","index":8,"name":"renderArgs"},"done":1320012478272,"duration":0},{"info":{"type":"global-middleware","index":9,"name":""},"done":1320012478272,"duration":0},{"info":{"type":"global-middleware","index":10,"name":""},"done":1320012478272,"duration":0},{"info":{"type":"global-middleware","index":11,"name":"static"},"done":1320012478272,"duration":0},{"info":{"type":"route-middleware","index":0,"path":"/?","method":"get","name":""},"done":1320012478273,"duration":0},{"info":{"type":"route-middleware","index":1,"path":"/?","method":"get","name":"recordRate"},"done":1320012478273,"duration":0},{"info":{"type":"route-middleware","index":2,"path":"/?","method":"get","name":"pageListen"},"done":1320012478273,"duration":0},{"info":{"type":"route-middleware","index":3,"path":"/?","method":"get","name":"pageSender"},"done":1320012478274,"duration":1},{"info":{"type":"route-middleware","index":4,"path":"/?","method":"get","name":"countVisits"},"done":1320012478275,"duration":1},{"info":{"type":"controller","index":0,"path":"/","method":"GET","status":200},"done":1320012478275,"duration":0}]

Options:

  • print
false

Logs to console the profile of each controller request.

  • printStatic
false

Logs to console the profile of each static request.

  • setHeaders
true

Writes request header X-Response-Duration for the duration of the request in milliseconds, and header X-Response-Time for the time when the server finished rendering the request. These can be used in conjunction with the client-side window.performance object to generate how long the entire request took both on the serverside and clientside.

  • printRequestLatency
printRequestLatency: function (req, requestDuration) {
        
    console.log('Request ' + req.url + ' duration : ' + requestDuration + ' ms');

    req.latency.forEach(function (point) {
        console.info('\t Info ' + JSON.stringify(point.info) + 
            ' duration : ' + point.duration + ' ms');
    });
}

Customize the function that prints latency information into the console.

TO-DOs

  • Aggregate latency across requests into the app object
  • Provide a page where page latency can be accessed
  • Add tests :)
  • Make a GeckoBoard widget