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

chronometrist

v0.1.1

Published

А console timekeeping tool for Express server requests

Downloads

14

Readme

chronometrist

А tool to draw waterfall of timings in stdout of an Express nodejs application

I guess your Express application makes some async work before preparing a response to the user, and you might want to see how long does some parts of that work take — especially, but not only, HTTP requests to your backends. If you are a frontend developer, I guess you are familiar with "Waterfall" view on the "Network" pane of Chrome's developer tools, and might want to have something similar here on your server. Here it is:

An example of chronometrist console output

Usage

The library is maximally robust to fit any situation you need. At the moment 0 (from which you want to start timeline to flow) you just create an instance, passing config and Express request and response objects to it:

const chronometrist = new Chronometrist({ enabled: true }, req, res);

It attaches a handler to request's end event and prints summary to console on request end.

Then, whan you want to measure a specific part of code, you just call in the beginning

const h = chronometrist.start('something', { some: params });

store a returned handler somewhere, and when this part reaches its end, call:

h.end();

or, if you think your part failed:

h.error(err);

Here you may pass an Error object, its message or statusCode property will be printed.

So, if you wrap your favorite server request library (got, asker, request etc.) with these .start and .end, you will essentially get a DevTools "Network" pane in your console.

Config options

All config fields are optional (but default values are such that summary won't show up at all).

enabled

Boolean, default: false

If false, Chronometrist does nothing. You actually want all this stuff as a debug output, so just enable Chronometrist in development environment

logThreshold

Number, default: 1000

Log only requests that took (between new Chronometrist() and request's end event) more milliseconds than this value. You might want to enable Chronometrist in production, but log only exccessively long requests to determine what makes them so long.

screenWidth

Number, default: 100

Number of characters to fit the whole timeline in. Timeline is always that wide, only the scale changes depending on how long did the request take.

redThreshold

Number, default: 500

Any operations that took more than this will be painted red

yellowThreshold

Number, default: 200

Any operations that took more than this will be painted yellow

totalRedThreshold

Number, default: 1000

If a whole request took more than this, a string "Comlete in XXX ms" will be printed in red. Note that if request returned a non-200 status code, this phrase will always be red

totalYellowThreshold

Number, default: 500

If a whole request took more than this, a string "Comlete in XXX ms" will be printed in yellow

shouldSkip()

function(req, res), default: () => false

You may add some custom logic here to extend enabled and logThreshold behavior. Just return true to prevent diagram from appearing. Function takes Express request and response as parameters

getOverallTitle()

function(req, res), default: req => req.path

A part of heading after "Request summary of...". Function takes Express request and response as parameters

getOverallInfo()

function(req, res), default: () => ''

Text that is shown after the title in gray. You might write here, for example, a request ID to simply find in your logs. Function takes Express request and response as parameters

filterQuery()

function(req, key, value), default: () => true

Params you pass to chronometrist.start as a second argument are filtered against this function. For example, you may add a bunch of specific query parameters to every request you issue. If you just wrap your HTTP library and pass query to start, you will have all of them show up in your diagram, which will break the layout. You may use filter to show only different and meaningful ones.

roundTo

Number, default: 1

Every millisecond value is rounded to this modulo. Actually, it was needed for tests to prevent them from flapping

log

function(string), default: console.log

Any function to call for printing result instead of console.log. You might want to store output in a file or send it somewhere instead of printing to stdout.

useColors

Boolean, default: true

When true, result is colored. When false, result is plain. When result is plain, yellowThreshold, redThreshold, totalYellowThreshold and totalRedThreshold obviously have no effect.