{"id":19621311,"url":"https://github.com/commenthol/connect-composer-stats","last_synced_at":"2025-08-25T00:37:27.763Z","repository":{"id":57205679,"uuid":"43023883","full_name":"commenthol/connect-composer-stats","owner":"commenthol","description":"Statistics for connect-composer middlewares","archived":false,"fork":false,"pushed_at":"2015-09-25T05:24:49.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-10T10:52:52.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/commenthol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-23T20:04:32.000Z","updated_at":"2015-09-23T20:05:32.000Z","dependencies_parsed_at":"2022-09-18T01:32:32.120Z","dependency_job_id":null,"html_url":"https://github.com/commenthol/connect-composer-stats","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/commenthol/connect-composer-stats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fconnect-composer-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fconnect-composer-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fconnect-composer-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fconnect-composer-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commenthol","download_url":"https://codeload.github.com/commenthol/connect-composer-stats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commenthol%2Fconnect-composer-stats/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265625570,"owners_count":23800624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T11:22:19.252Z","updated_at":"2025-07-17T16:04:14.578Z","avatar_url":"https://github.com/commenthol.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connect-composer-stats\n\n\u003e Statistics for connect-composer middlewares\n\n[![NPM version](https://badge.fury.io/js/connect-composer-stats.svg)](https://www.npmjs.com/package/connect-composer-stats/)\n[![Build Status](https://secure.travis-ci.org/commenthol/connect-composer-stats.svg?branch=master)](https://travis-ci.org/commenthol/connect-composer-stats)\n\nEnable runtime measurements for composed middlewares using [connect-composer][] to track down latency problems within middlewares.\n\nInject either globally or locally into your composed middlewares and dump results into a CVS file.\n\n## Table of Contents\n\n\u003c!-- !toc (minlevel=2 omit=\"Table of Contents\") --\u003e\n\n* [Description](#description)\n  * [Set globally for all composed middlewares](#set-globally-for-all-composed-middlewares)\n  * [Set locally for a single composed middlewares](#set-locally-for-a-single-composed-middlewares)\n  * [Wrap arround a single middleware function](#wrap-arround-a-single-middleware-function)\n* [Methods](#methods)\n  * [stats()](#stats)\n  * [from(fn)](#fromfn)\n  * [dump(options)](#dumpoptions)\n  * [data](#data)\n* [Contribution and License Agreement](#contribution-and-license-agreement)\n* [License](#license)\n* [References](#references)\n\n\u003c!-- toc! --\u003e\n\n## Description\n\n### Set globally for all composed middlewares\n\n```js\nvar composestats = require('connect-composer-stats')\nvar compose = require('connect-composer')\n// get new stats object\nvar stats = composestats()\n// globally inject stats use:\ncompose.options = { stats: stats.from }\n\n// a middleware function\nvar mw = function (req, res, next) { next() }\n// composing the single middlewares\nvar mws = compose (mw, mw, mw, mw)\nvar req = {}, res = {}\n\nmws(req, res, function () {\n  console.log(stats.data)\n})\n```\n\n### Set locally for a single composed middlewares\n\n```js\nvar composestats = require('connect-composer-stats')\nvar compose = require('connect-composer')\n// get new stats object\nvar stats = composestats()\n\n// a middleware function\nvar mw = function (req, res, next) { next() }\n// composing the single middlewares\nvar mws = compose (mw, mw, mw, mw)\n// locally inject stats use:\nmws.options = { stats: stats.from }\n\nvar req = {}, res = {}\n\nmws(req, res, function () {\n  console.log(stats.data)\n})\n```\n\n### Wrap arround a single middleware function\n\n```js\nvar composestats = require('connect-composer-stats')\nvar compose = require('connect-composer')\n// get new stats object\nvar stats = composestats()\n\n// a middleware function\nvar mw = function (req, res, next) { next() }\n// wrapping the stats middleware\nvar wrap = stats.from(mw)\n\nvar req = {}, res = {}\n\nwrap(req, res, function () {\n  wrap(req, res, function () {\n    console.log(stats.data)\n  })\n})\n```\n\n## Methods\n\n### stats()\n\ncreate statistics for middleware(s)\n\n**Returns**: `Object`, object with functions\n\n\n### from(fn)\n\ntake statistics from middleware function `fn`\n\n**Parameters**\n\n**fn**: `function`, middleware function from which to generate the statistics\n\n**Returns**: `function`, wrapped middleware function\n\n\n### dump(options)\n\nDump the collected statistics into a csv file or to stdout\n\n**Parameters**\n\n**options**: `Object`, options\n  * ns: false,          // {Boolean} if `false` output is in milliseconds; if `true` then nanoseconds\n  * dir: process.cwd(), // {String} dir where stats files are written; default current working dir\n  * csv: true,          // {Boolean} of `true` output csv to filesystem; default `true`\n  * sortkey: 'total'    // {String} key to reverse sort (total, average, max, min)\n\n**Returns**: `String`, filename of csv file\n\n\n### data\n\nThe data object where the statistics for each function are stored\n\n**Example**\n\n```js\n{ './example.js:16:19:mwG':\n   { name: './example.js:16:19:mwG', // file, line, column and name of function called\n     count: 3,                       // number of function calls\n     total: 6389,                    // time in nanoseconds\n     min: 826,\n     max: 2923 },\n  './example.js:14:18:mw':\n   { name: './example.js:14:18:mw',\n     count: 2,\n     total: 1662,\n     min: 742,\n     max: 920 } }\n```\n\n## Contribution and License Agreement\n\nIf you contribute code to this project, you are implicitly allowing your\ncode to be distributed under the MIT license. You are also implicitly\nverifying that all code is your original work or correctly attributed\nwith the source of its origin and licence.\n\n## License\n\nCopyright (c) 2015 commenthol (MIT License)\n\nSee [LICENSE][] for more info.\n\n## References\n\n\u003c!-- !ref --\u003e\n\n* [connect-composer][connect-composer]\n* [LICENSE][LICENSE]\n\n\u003c!-- ref! --\u003e\n\n[LICENSE]: ./LICENSE\n[connect-composer]: https://github.com/commenthol/connect-composer\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fconnect-composer-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommenthol%2Fconnect-composer-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommenthol%2Fconnect-composer-stats/lists"}