https://www.npmjs.com/package/serve-favicon
Node.js middleware for serving a favicon.
A favicon is a visual cue that client software, like browsers, use to identify a site. For an example and more information, please visit the Wikipedia article on favicons.
Why use this module?
favicon.ico
frequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.ETag
based on the contents of the icon, rather than file system properties.Content-Type
.Note This module is exclusively for serving the "default, implicit favicon", which is GET /favicon.ico
. For additional vendor-specific icons that require HTML markup, additional middleware is required to serve the relevant files, for example serve-static.
This is a Node.js module available through the npm registry. Installation is done using the npm install
command:
$ npm install serve-favicon
Create new middleware to serve a favicon from the given path
to a favicon file. path
may also be a Buffer
of the icon to serve.
Serve favicon accepts these properties in the options object.
The cache-control
max-age
directive in ms
, defaulting to 1 year. This can also be a string accepted by the ms module.
Typically this middleware will come very early in your stack (maybe even first) to avoid processing any other middleware if we already know the request is for /favicon.ico
.
var express = var favicon = var path = var app = app // Add your routes here, etc. app
var connect = var favicon = var path = var app = app // Add your middleware here, etc. app
This middleware can be used anywhere, even outside express/connect. It takes req
, res
, and callback
.
var http = var favicon = var finalhandler = var path = var _favicon = var server = http server