{"id":13708009,"url":"https://github.com/expressjs/serve-favicon","last_synced_at":"2026-03-16T02:28:30.166Z","repository":{"id":13817835,"uuid":"16514286","full_name":"expressjs/serve-favicon","owner":"expressjs","description":"favicon serving middleware","archived":false,"fork":false,"pushed_at":"2025-04-17T14:13:36.000Z","size":107,"stargazers_count":622,"open_issues_count":2,"forks_count":73,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-05T09:37:54.052Z","etag":null,"topics":["expressjs","favicon","javascript","middleware","nodejs"],"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/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,"zenodo":null},"funding":{"open_collective":"express"}},"created_at":"2014-02-04T14:34:06.000Z","updated_at":"2025-04-17T14:13:41.000Z","dependencies_parsed_at":"2025-05-02T11:45:22.808Z","dependency_job_id":null,"html_url":"https://github.com/expressjs/serve-favicon","commit_stats":{"total_commits":206,"total_committers":8,"mean_commits":25.75,"dds":0.05339805825242716,"last_synced_commit":"15fe5e3837cef1e88cb4d1112bc2a23674b4834b"},"previous_names":["expressjs/favicon"],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-favicon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-favicon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-favicon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-favicon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expressjs","download_url":"https://codeload.github.com/expressjs/serve-favicon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253360647,"owners_count":21896373,"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":["expressjs","favicon","javascript","middleware","nodejs"],"created_at":"2024-08-02T22:01:52.871Z","updated_at":"2026-03-16T02:28:30.137Z","avatar_url":"https://github.com/expressjs.png","language":"JavaScript","funding_links":["https://opencollective.com/express"],"categories":["JavaScript","中间件","Middleware"],"sub_categories":[],"readme":"# serve-favicon\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Linux Build Status][ci-image]][ci-url]\n[![Windows Build][appveyor-image]][appveyor-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n\nNode.js middleware for serving a favicon.\n\nA favicon is a visual cue that client software, like browsers, use to identify\na site. For an example and more information, please visit\n[the Wikipedia article on favicons](https://en.wikipedia.org/wiki/Favicon).\n\nWhy use this module?\n\n  - User agents request `favicon.ico` frequently and indiscriminately, so you\n    may wish to exclude these requests from your logs by using this middleware\n    before your logger middleware.\n  - This module caches the icon in memory to improve performance by skipping\n    disk access.\n  - This module provides an `ETag` based on the contents of the icon, rather\n    than file system properties.\n  - This module will serve with the most compatible `Content-Type`.\n\n**Note** This module is exclusively for serving the \"default, implicit favicon\",\nwhich is `GET /favicon.ico`. For additional vendor-specific icons that require\nHTML markup, additional middleware is required to serve the relevant files, for\nexample [serve-static](https://npmjs.org/package/serve-static).\n\n## Install\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 serve-favicon\n```\n\n## API\n\n### favicon(path, options)\n\nCreate new middleware to serve a favicon from the given `path` to a favicon file.\n`path` may also be a `Buffer` of the icon to serve.\n\n#### Options\n\nServe favicon accepts these properties in the options object.\n\n##### maxAge\n\nThe `cache-control` `max-age` directive in `ms`, defaulting to 1 year. This can\nalso be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)\nmodule.\n\n## Examples\n\nTypically this middleware will come very early in your stack (maybe even first)\nto avoid processing any other middleware if we already know the request is for\n`/favicon.ico`.\n\n### express\n\n```javascript\nvar express = require('express')\nvar favicon = require('serve-favicon')\nvar path = require('path')\n\nvar app = express()\napp.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))\n\n// Add your routes here, etc.\n\napp.listen(3000)\n```\n\n### connect\n\n```javascript\nvar connect = require('connect')\nvar favicon = require('serve-favicon')\nvar path = require('path')\n\nvar app = connect()\napp.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))\n\n// Add your middleware here, etc.\n\napp.listen(3000)\n```\n\n### vanilla http server\n\nThis middleware can be used anywhere, even outside express/connect. It takes\n`req`, `res`, and `callback`.\n\n```javascript\nvar http = require('http')\nvar favicon = require('serve-favicon')\nvar finalhandler = require('finalhandler')\nvar path = require('path')\n\nvar _favicon = favicon(path.join(__dirname, 'public', 'favicon.ico'))\n\nvar server = http.createServer(function onRequest (req, res) {\n  var done = finalhandler(req, res)\n\n  _favicon(req, res, function onNext (err) {\n    if (err) return done(err)\n\n    // continue to process the request here, etc.\n\n    res.statusCode = 404\n    res.end('oops')\n  })\n})\n\nserver.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-favicon/master.svg?label=windows\n[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-favicon\n[ci-image]: https://badgen.net/github/checks/expressjs/serve-favicon/master?label=ci\n[ci-url]: https://github.com/expressjs/serve-favicon/actions/workflows/ci.yml\n[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-favicon.svg\n[coveralls-url]: https://coveralls.io/r/expressjs/serve-favicon?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/serve-favicon.svg\n[downloads-url]: https://npmjs.org/package/serve-favicon\n[npm-image]: https://img.shields.io/npm/v/serve-favicon.svg\n[npm-url]: https://npmjs.org/package/serve-favicon\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fserve-favicon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpressjs%2Fserve-favicon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fserve-favicon/lists"}