{"id":18801844,"url":"https://github.com/mitscherlich/koa2-servertime","last_synced_at":"2026-04-29T22:32:00.902Z","repository":{"id":45731433,"uuid":"514252023","full_name":"Mitscherlich/koa2-servertime","owner":"Mitscherlich","description":"Add `server-timing` headers to your koa.js server.","archived":false,"fork":false,"pushed_at":"2022-08-08T16:20:22.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-01-30T08:08:24.702Z","etag":null,"topics":["koa","server-timing"],"latest_commit_sha":null,"homepage":"https://npm.im/koa2-servertime","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/Mitscherlich.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":"2022-07-15T11:54:41.000Z","updated_at":"2024-04-09T11:29:48.000Z","dependencies_parsed_at":"2022-09-26T21:30:25.467Z","dependency_job_id":null,"html_url":"https://github.com/Mitscherlich/koa2-servertime","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mitscherlich%2Fkoa2-servertime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mitscherlich%2Fkoa2-servertime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mitscherlich%2Fkoa2-servertime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mitscherlich%2Fkoa2-servertime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mitscherlich","download_url":"https://codeload.github.com/Mitscherlich/koa2-servertime/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239734644,"owners_count":19688257,"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":["koa","server-timing"],"created_at":"2024-11-07T22:25:29.444Z","updated_at":"2026-01-04T17:30:15.675Z","avatar_url":"https://github.com/Mitscherlich.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa2-servertime\n\n[![npm version](https://badgen.net/npm/v/koa2-servertime)](https://npm.im/koa2-servertime) [![npm downloads](https://badgen.net/npm/dm/koa2-servertime)](https://npm.im/koa2-servertime)\n\n## Install\n\nvia `pnpm`, `yarn` or `npm`:\n\n```bash\npnpm add koa2-servertime\n# or\nyarn add koa2-servertime\n# or\nnpm i -S koa2-servertime\n```\n\n## Usage\n\nSimply add this middleware to your koa application:\n\n```js\nconst Koa = require('koa')\nconst ServerTime = require('koa2-servertime')\nconst app = new Koa()\n\napp.use(ServerTime())\n\napp.use(async (ctx) =\u003e {\n  // async\n  await ctx.startTimePromise('api', 'Fetch Data', fetch(/* ... */))\n  await ctx.startTimePromise('db', 'Query Database', db.query(/* ... */))\n  await ctx.startTimePromise('cache', 'Get from Cache', cache.get(/* ... */))\n\n  // synchronous\n  ctx.startTime('render', 'Render Content')\n  ctx.body = render(/* ... */)\n  ctx.endTime('render')\n})\n```\n\nThis middleware will give you three apis for collecting timing information:\n\n- `ctx.startTimePromise`: start a timer and return a promise, ended automatically when the promise settled.\n- `ctx.startTime`: start a timer\n- `ctx.endTime`: end a timer\n\nIf you want to disable/enable this middleware, you can simply set `enabled` property to `false` or `true`.\n\nFor example, only enable it for development:\n\n```js\napp.use(ServerTime({\n  enabled: process.env.NODE_ENV !== 'production',\n}))\n```\n\nThis middleware will automatically add a `Total Response Time` header to the response. You can disable or modify it with options.\n\n```js\napp.use(ServerTime({\n  total: true, // by default\n  totalName: 'total', // by default\n  totalDesc: 'Total Response Time', // by default\n}))\n```\n\nFor more detail, checkout [./example/app.js](./example/app.js).\n\n### Options\n\n- `enabled`: enable/disable this middleware. default: `true`\n- `total`: enable/disable total response time. default: `true`\n- `totalName`: total response time header name. default: `'total'`\n- `totalDesc`: total response time header description. default: `'Total Response Time'`\n\n## License\n\nMIT \u0026copy; [Mitscherlich](https://mitscherlich.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitscherlich%2Fkoa2-servertime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitscherlich%2Fkoa2-servertime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitscherlich%2Fkoa2-servertime/lists"}