3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Build Status][travis-image]][travis-url]
6 [![Test Coverage][coveralls-image]][coveralls-url]
7 [![Gittip][gittip-image]][gittip-url]
9 Node.js middleware for serving a favicon.
13 - User agents request `favicon.ico` frequently and indiscriminately, so you
14 may wish to exclude these requests from your logs by using this middleware
15 before your logger middleware.
16 - This module caches the icon in memory to improve performance by skipping
18 - This module provides an `ETag` based on the contents of the icon, rather
19 than file system properties.
20 - This module will serve with the most compatible `Content-Type`.
25 npm install serve-favicon
30 ### favicon(path, options)
32 Create new middleware to serve a favicon from the given `path` to a favicon file.
33 `path` may also be a `Buffer` of the icon to serve.
37 Serve favicon accepts these properties in the options object.
41 The `cache-control` `max-age` directive in `ms`, defaulting to 1 day. This can
42 also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
47 Typically this middleware will come very early in your stack (maybe even first)
48 to avoid processing any other middleware if we already know the request is for
54 var express = require('express');
55 var favicon = require('serve-favicon');
58 app.use(favicon(__dirname + '/public/favicon.ico'));
60 // Add your routes here, etc.
68 var connect = require('connect');
69 var favicon = require('serve-favicon');
72 app.use(favicon(__dirname + '/public/favicon.ico'));
74 // Add your middleware here, etc.
79 ### vanilla http server
81 This middleware can be used anywhere, even outside express/connect. It takes
82 `req`, `res`, and `callback`.
85 var http = require('http');
86 var favicon = require('serve-favicon');
87 var finalhandler = require('finalhandler');
89 var _favicon = favicon(__dirname + '/public/favicon.ico');
91 var server = http.createServer(function onRequest(req, res) {
92 var done = finalhandler(req, res);
94 _favicon(req, res, function onNext(err) {
95 if (err) return done(err);
97 // continue to process the request here, etc.
111 [npm-image]: https://img.shields.io/npm/v/serve-favicon.svg?style=flat
112 [npm-url]: https://npmjs.org/package/serve-favicon
113 [travis-image]: https://img.shields.io/travis/expressjs/serve-favicon.svg?style=flat
114 [travis-url]: https://travis-ci.org/expressjs/serve-favicon
115 [coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-favicon.svg?style=flat
116 [coveralls-url]: https://coveralls.io/r/expressjs/serve-favicon?branch=master
117 [downloads-image]: https://img.shields.io/npm/dm/serve-favicon.svg?style=flat
118 [downloads-url]: https://npmjs.org/package/serve-favicon
119 [gittip-image]: https://img.shields.io/gittip/dougwilson.svg?style=flat
120 [gittip-url]: https://www.gittip.com/dougwilson/