{"name":"finalhandler","description":"Node.js final http responder","version":"2.1.1","author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/pillarjs/finalhandler.git"},"funding":{"type":"opencollective","url":"https://opencollective.com/express"},"dependencies":{"debug":"^4.4.0","encodeurl":"^2.0.0","escape-html":"^1.0.3","on-finished":"^2.4.1","parseurl":"^1.3.3","statuses":"^2.0.1"},"devDependencies":{"eslint":"^7.32.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.31.0","eslint-plugin-markdown":"^2.2.1","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^5.2.0","eslint-plugin-standard":"^4.1.0","mocha":"^11.0.1","nyc":"^17.1.0","supertest":"^7.0.0"},"engines":{"node":">= 18.0.0"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec --check-leaks test/","test-ci":"nyc --reporter=lcovonly --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test","test-inspect":"mocha --reporter spec --inspect --inspect-brk test/"},"_id":"finalhandler@2.1.1","gitHead":"aa2851f6b6cf48238a307299be691721530e9172","bugs":{"url":"https://github.com/pillarjs/finalhandler/issues"},"homepage":"https://github.com/pillarjs/finalhandler#readme","_nodeVersion":"22.10.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==","shasum":"a2c517a6559852bcdb06d1f8bd7f51b68fad8099","tarball":"http://registry-npm.ywwl.com/finalhandler/download/finalhandler-2.1.1.tgz","fileCount":5,"unpackedSize":18111,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDAEOwhThATX0axQ0v7EDpT8pa141rKbW5cEvReykNa2QIhAOAFcPGheB+ugzRjW5cHCl9+Rb3LTB0uH99eAmJwfkiK"}],"size":6341,"noattachment":false,"key":"/finalhandler/-/finalhandler-2.1.1.tgz"},"_npmUser":{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},"directories":{},"maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/finalhandler_2.1.1_1764605101885_0.5285530536043159"},"_hasShrinkwrap":false,"readme":"# finalhandler\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-image]][node-url]\n[![Build Status][github-actions-ci-image]][github-actions-ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]\n\nNode.js function to invoke as the final step to respond to HTTP request.\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 finalhandler\n```\n\n## API\n\n```js\nconst finalhandler = require('finalhandler')\n```\n\n### finalhandler(req, res, [options])\n\nReturns function to be invoked as the final step for the given `req` and `res`.\nThis function is to be invoked as `fn(err)`. If `err` is falsy, the handler will\nwrite out a 404 response to the `res`. If it is truthy, an error response will\nbe written out to the `res` or `res` will be terminated if a response has already\nstarted.\n\nWhen an error is written, the following information is added to the response:\n\n  * The `res.statusCode` is set from `err.status` (or `err.statusCode`). If\n    this value is outside the 4xx or 5xx range, it will be set to 500.\n  * The `res.statusMessage` is set according to the status code.\n  * The body will be the HTML of the status code message if `env` is\n    `'production'`, otherwise will be `err.stack`.\n  * Any headers specified in an `err.headers` object.\n\nThe final handler will also unpipe anything from `req` when it is invoked.\n\n#### options.env\n\nBy default, the environment is determined by `NODE_ENV` variable, but it can be\noverridden by this option.\n\n#### options.onerror\n\nProvide a function to be called with the `err` when it exists. Can be used for\nwriting errors to a central location without excessive function generation. Called\nas `onerror(err, req, res)`.\n\n## Examples\n\n### always 404\n\n```js\nconst finalhandler = require('finalhandler')\nconst http = require('http')\n\nconst server = http.createServer((req, res) => {\n  const done = finalhandler(req, res)\n  done()\n})\n\nserver.listen(3000)\n```\n\n### perform simple action\n\n```js\nconst finalhandler = require('finalhandler')\nconst fs = require('fs')\nconst http = require('http')\n\nconst server = http.createServer((req, res) => {\n  const done = finalhandler(req, res)\n\n  fs.readFile('index.html', (err, buf) => {\n    if (err) return done(err)\n    res.setHeader('Content-Type', 'text/html')\n    res.end(buf)\n  })\n})\n\nserver.listen(3000)\n```\n\n### use with middleware-style functions\n\n```js\nconst finalhandler = require('finalhandler')\nconst http = require('http')\nconst serveStatic = require('serve-static')\n\nconst serve = serveStatic('public')\n\nconst server = http.createServer((req, res) => {\n  const done = finalhandler(req, res)\n  serve(req, res, done)\n})\n\nserver.listen(3000)\n```\n\n### keep log of all errors\n\n```js\nconst finalhandler = require('finalhandler')\nconst fs = require('fs')\nconst http = require('http')\n\nconst server = http.createServer((req, res) => {\n  const done = finalhandler(req, res, { onerror: logerror })\n\n  fs.readFile('index.html', (err, buf) => {\n    if (err) return done(err)\n    res.setHeader('Content-Type', 'text/html')\n    res.end(buf)\n  })\n})\n\nserver.listen(3000)\n\nfunction logerror (err) {\n  console.error(err.stack || err.toString())\n}\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/finalhandler.svg\n[npm-url]: https://npmjs.org/package/finalhandler\n[node-image]: https://img.shields.io/node/v/finalhandler.svg\n[node-url]: https://nodejs.org/en/download\n[coveralls-image]: https://img.shields.io/coveralls/pillarjs/finalhandler.svg\n[coveralls-url]: https://coveralls.io/r/pillarjs/finalhandler?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/finalhandler.svg\n[downloads-url]: https://npmjs.org/package/finalhandler\n[github-actions-ci-image]: https://github.com/pillarjs/finalhandler/actions/workflows/ci.yml/badge.svg\n[github-actions-ci-url]: https://github.com/pillarjs/finalhandler/actions/workflows/ci.yml\n[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/pillarjs/finalhandler/badge\n[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/pillarjs/finalhandler","publish_time":1764605102140,"_cnpm_publish_time":1764605102140,"dist-tags":{"latest":"2.1.1","latest-1.x":"1.3.2"}}