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 🙏

© 2026 – Pkg Stats / Ryan Hefner

time-using-middleware

v0.5.1

Published

To measure time

Readme

time-using-middleware

NPM version Downloads License

A tool to collect time cost for requests, waiting for HTML back, rendering page and etc., also it can export performance testing reports to HTML & pdf easily.

Features

  • Export Table Reports using Command Line window in Markdown format
  • Recording the data of each page session
  • Record pages by Regex Expression filters defined in Options
  • Complete the page collect session until it recieve the COMPLETE signal by timeUsingMiddlewareCollectFinish
  • Support those Pages which are consist of by both Nodejs side render and Front-end JS work. The cookie mtKey can tracking all of them
  • All the time attributes are defined by Developers(You)

Notice

This timing tool is under constructing right now, currenlty I'm using it to measure performance when calling APIs from nodejs, and support collect all the key-value pair data throung two public methods: addTimeRecord & finishRecording.

So, it need users(usually developers) to write some codes in their project to collect data and send back to this middleware. All the log files will stored in which you specified in the options.

mtKey

The cookie which will be set to the client if the page's url was included in patterns above. And it will be removed finally when the current measuring session finish (means done: 1 was recieved by time-using-middleware collection api) or will be replaced by a new one.

Installation

$ npm install time-using-middleware --save

How to Use

Usage: timeUsing [options]

Options:

-h, --help               output usage information
-V, --version            output the version number
-i, --input [path]       where the log files read from
-o, --output [path]      where the report put to
-c, --pageconfig [path]  all configs for each pages
-f, --format <types>     the format of the exported file

format -f

Specify which format of files you want to export, default to CL screen, otherwise, it should be in HTML and PDF.

timeUsing -i ./log/timeUsing/ -c ./timeUsing.json -f html,pdf

HTML Report Preview

HTML Report

Command Line Report Preview

-------------------------------------------------
      Time Using Middleware by Staydan.com       

                                    v0.4.3     
-------------------------------------------------

30ms -  analyzing log data finished...
contain pages counts: 2
 Analyzing For [ timeUsingTestPage ]
validSampleCounts: 1156

42ms - assembling data...
samples counts for PAGE [ timeUsingTestPage ] : 1156 / 1156 (valid / sum)
 Analyzing For [ testDemoPage ]
validSampleCounts: 7159

109ms - assembling data...
samples counts for PAGE [ testDemoPage ] : 7159 / 7159 (valid / sum)
6ms - preparing the table data...

------- Performance Testing Results -------

Page : timeUsingTestPage

|                 | Sample Count | average(ms) | median(ms) | min(ms) | max(ms) |
| :-------------- | :----------: | :---------: | :--------: | :-----: | :-----: |
| Test API        |     1156     |    1026.1   |   1039.5   |    7    |   2489  |
| Node All API(n) |     1156     |    1026.4   |   1039.5   |    8    |   2502  |
| FirstScreen Dom |     1156     |    1060.3   |   1072.5   |    37   |   2585  |


0ms - finish render data
4ms - preparing the table data...

------- Performance Testing Results -------

Page : testDemoPage

|                 | Sample Count | average(ms) | median(ms) | min(ms) | max(ms) |
| :-------------- | :----------: | :---------: | :--------: | :-----: | :-----: |
| Test API        |     7159     |    992.2    |     985    |    2    |   2514  |
| Node All API(n) |     7159     |    992.3    |     986    |    2    |   2522  |
| FirstScreen Dom |     7159     |    1025.8   |    1011    |    20   |   2738  |


1ms - finish render data
Exporting file in HTML finished

-------------------------------------------------
       Time Using Middleware by Staydan.com      

   Collect Data & Analyze Logs & Export Reports  
-------------------------------------------------

How to Integrate with your app(Examples)

Node side js

var express      = require('express')
var measureTime = require('time-using-middleware')

var app = express()

// Only the originalUrl match the pattern (Usually match the specified falg 'staydan-performance-testing'), this page visit will be tracked by this time-using-middleware
var measureUrlPatterns = [
    {
        pattern: /^\/detail\/content.*staydan-performance-testing$/,
        pageName: 'detailContent'
    },
    {
        pattern: /^\/announcement.*staydan-performance-testing$/,
        pageName: 'announcement'
    }
];

// All the log files will be stored under `/log/timeUsing/` on your server
app.use(timeUsingMiddleware({
    measureUrlPatterns: measureUrlPatterns,
    logPath: '/log/timeUsing/',
    runtimePath: path.resolve(__dirname, './')
}));

app.get('/detail/content', function(req, res) {
    res.render('/page/content', {data: data});
})

// Expose two Public APIs to your app
// It can collect data and finish a collect session
app.post('/tu/finish', timeUsingMiddlewareCollectFinish);
app.post('/tu/add', timeUsingMiddlewareCollectAdd);

function timeUsingMiddlewareCollectFinish(req, res, next) {
    var data = req.body;

    if (req.cookies.mtKey) {
        data.mtKey = req.cookies.mtKey;
        timeUsingMiddleware.finishRecording(res, data, {
            success: function () {
                res.send({code: 200});
            },
            error: function () {
                res.send({code: 0});
            }
        });
    }
    else {
        res.send({code: 0});
    }
}

function timeUsingMiddlewareCollectAdd(req, res, next) {
    var data = req.body;

    if (req.cookies.mtKey) {
        data.mtKey = req.cookies.mtKey;
        timeUsingMiddleware.addTimeRecord(data, {
            success: function () {
                res.send({code: 200});
            },
            error: function () {
                res.send({code: 0});
            }
        });
    }
    else {
        res.send({code: 0});
    }
}
app.listen(8080)

Client side js

// Time collected in front-end side
// widgetContentLoaded & DOMContentLoaded is timestamp format
// it need to be calculated carefully when exporting report
var timeCostCollected = {
    'allFeApiFinishTime': 186,
    '/staydan/v1/game/list': 170,
    '/staydan/v1/tool/list': 172,
    '/staydan/v1/extension/list': 174,
    '/staydan/v1/share': 181,
    'widgetContentLoaded': 1463713604103,
    'DOMContentLoaded': 1463713603376
}

// Send back the time data to middleware to be managed
util.post('/tu/finish', timeCostCollected)
    .then(function (tuResponse) {
        console.log(tuResponse);
    })
    .always(function () {
        window.location.reload();
    });

Options

domain (Deprecated)

[String, Optional] mtKey use this, it always be the host of your website.

pageConfig (not supported)

[JSON, Optional] use this to calc the time attributes and export them to the reports.

/**
 * Definition how to calc all the attributes read from log file
 *
 * key                  The label of each Row within the reports
 * formula: <string>    Direclty use it to be calculated
 *          <array>     formula[0] - formula[1] - formula[2] -...
 *                      The final result will be used in report
 * 
 * @type {Array}
 */
[
    {
        "pageName": "timeUsingTestPage",
        "configs": [
            {
                "key": "Test API",
                "formula": "/test"
            },
            {
                "key": "Node All API(n)",
                "formula": "allNodeApiFinishTime"
            },
            {
                "key": "FirstScreen Dom",
                "formula": [
                    "DOMContentLoaded",
                    "pageStart"
                ]
            }
        ]
    },
    {
        "pageName": "testDemoPage",
        "configs": [
            {
                "key": "Test API",
                "formula": "/test"
            },
            {
                "key": "Node All API(n)",
                "formula": "allNodeApiFinishTime"
            },
            {
                "key": "FirstScreen Dom",
                "formula": [
                    "DOMContentLoaded",
                    "pageStart"
                ]
            }
        ]
    }
]

measureUrlPatterns

[Array, Required] Define the patterns, it can be regex expression as well. time-using-middleware will check the patterns when the request come.

logPath

[String, Required] Define the path where time-using-middleware middleware store the log files.

MIT Licensed @staydan.com 2016