serve-favicon
Node.js middleware for serving a favicon.
Install
npm install serve-favicon
API
favicon(path, options)
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.
Options
Serve favicon accepts these properties in the options object.
maxAge
The cache-control
max-age
directive in ms
, defaulting to 1 day. This can
also be a string accepted by the ms
module.
Examples
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
.
express
var express = ;var favicon = ; var app = ;app; // Add your routes here, etc. app;
multiple icons
app;
connect
var connect = ;var favicon = ; var app = ;app; // Add your middleware here, etc. app;
vanilla http server
This middleware can be used anywhere, even outside express/connect. It takes
req
, res
, and callback
.
var http = ;var favicon = ;var finalhandler = ; var _favicon = ; var server = http; server;