{"id":14957519,"url":"https://github.com/expressjs/response-time","last_synced_at":"2025-05-13T23:07:56.099Z","repository":{"id":13950245,"uuid":"16650307","full_name":"expressjs/response-time","owner":"expressjs","description":"Response time header for node.js","archived":false,"fork":false,"pushed_at":"2024-10-22T11:35:21.000Z","size":64,"stargazers_count":465,"open_issues_count":3,"forks_count":70,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-29T14:24:24.449Z","etag":null,"topics":["javascript","middleware","nodejs","response-time"],"latest_commit_sha":null,"homepage":"","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/expressjs.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"express"}},"created_at":"2014-02-08T18:51:40.000Z","updated_at":"2024-10-24T18:57:52.000Z","dependencies_parsed_at":"2024-11-26T15:15:11.673Z","dependency_job_id":null,"html_url":"https://github.com/expressjs/response-time","commit_stats":{"total_commits":99,"total_committers":5,"mean_commits":19.8,"dds":0.04040404040404044,"last_synced_commit":"050ed4a9bfffe7c7970345168cf06534e48f426d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fresponse-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fresponse-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fresponse-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fresponse-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expressjs","download_url":"https://codeload.github.com/expressjs/response-time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154073,"owners_count":21056536,"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":["javascript","middleware","nodejs","response-time"],"created_at":"2024-09-24T13:15:02.635Z","updated_at":"2025-04-10T03:38:48.840Z","avatar_url":"https://github.com/expressjs.png","language":"JavaScript","readme":"# response-time\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Node.js Version][node-image]][node-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nResponse time for Node.js servers.\n\nThis module creates a middleware that records the response time for\nrequests in HTTP servers. The \"response time\" is defined here as the\nelapsed time from when a request enters this middleware to when the\nheaders are written out to the client.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install response-time\n```\n\n## API\n\n\u003c!-- eslint-disable no-unused-vars --\u003e\n\n```js\nvar responseTime = require('response-time')\n```\n\n### responseTime([options])\n\nCreate a middleware that adds a `X-Response-Time` header to responses. If\nyou don't want to use this module to automatically set a header, please\nsee the section about [`responseTime(fn)`](#responsetimefn).\n\n#### Options\n\nThe `responseTime` function accepts an optional `options` object that may\ncontain any of the following keys:\n\n##### digits\n\nThe fixed number of digits to include in the output, which is always in\nmilliseconds, defaults to `3` (ex: `2.300ms`).\n\n##### header\n\nThe name of the header to set, defaults to `X-Response-Time`.\n\n##### suffix\n\nBoolean to indicate if units of measurement suffix should be added to\nthe output, defaults to `true` (ex: `2.300ms` vs `2.300`).\n\n### responseTime(fn)\n\nCreate a new middleware that records the response time of a request and\nmakes this available to your own function `fn`. The `fn` argument will be\ninvoked as `fn(req, res, time)`, where `time` is a number in milliseconds.\n\n## Examples\n\n### express/connect\n\n```js\nvar express = require('express')\nvar responseTime = require('response-time')\n\nvar app = express()\n\napp.use(responseTime())\n\napp.get('/', function (req, res) {\n  res.send('hello, world!')\n})\n```\n\n### vanilla http server\n\n```js\nvar finalhandler = require('finalhandler')\nvar http = require('http')\nvar responseTime = require('response-time')\n\n// create \"middleware\"\nvar _responseTime = responseTime()\n\nhttp.createServer(function (req, res) {\n  var done = finalhandler(req, res)\n  _responseTime(req, res, function (err) {\n    if (err) return done(err)\n\n    // respond to request\n    res.setHeader('content-type', 'text/plain')\n    res.end('hello, world!')\n  })\n})\n```\n\n### response time metrics\n\n```js\nvar express = require('express')\nvar responseTime = require('response-time')\nvar StatsD = require('node-statsd')\n\nvar app = express()\nvar stats = new StatsD()\n\nstats.socket.on('error', function (error) {\n  console.error(error.stack)\n})\n\napp.use(responseTime(function (req, res, time) {\n  var stat = (req.method + req.url).toLowerCase()\n    .replace(/[:.]/g, '')\n    .replace(/\\//g, '_')\n  stats.timing(stat, time)\n}))\n\napp.get('/', function (req, res) {\n  res.send('hello, world!')\n})\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-version-image]: https://badgen.net/npm/v/response-time\n[npm-url]: https://npmjs.org/package/response-time\n[npm-downloads-image]: https://badgen.net/npm/dm/response-time\n[node-image]: https://badgen.net/npm/node/response-time\n[node-url]: https://nodejs.org/en/download\n[ci-image]: https://badgen.net/github/checks/express/response-time/master?label=ci\n[ci-url]: https://github.com/express/response-time/actions/workflows/ci.yml\n[coveralls-image]: https://badgen.net/coveralls/c/github/express/response-time/master\n[coveralls-url]: https://coveralls.io/r/express/response-time?branch=master\n","funding_links":["https://opencollective.com/express"],"categories":["中间件"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fresponse-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpressjs%2Fresponse-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fresponse-time/lists"}