Serve site icons (favicon.ico and apple-touch-icon.png and all its flavours) quickly and from any directory.
npm install --save git://github.com/theworkers/connect-favicons.gitfavicon.icofavicon.pngapple-touch-icon.pngapple-touch-icon-precomposed.pngapple-touch-icon-57x57.pngapple-touch-icon-57x57-precomposed.pngapple-touch-icon-72x72.pngapple-touch-icon-72x72-precomposed.pngapple-touch-icon-76x76.pngapple-touch-icon-76x76-precomposed.pngapple-touch-icon-114x114.pngapple-touch-icon-114x114-precomposed.pngapple-touch-icon-120x120.pngapple-touch-icon-120x120-precomposed.pngapple-touch-icon-144x144.pngapple-touch-icon-144x144-precomposed.pngapple-touch-icon-152x152.pngapple-touch-icon-152x152-precomposed.pngapple-touch-icon-180x180.pngapple-touch-icon-180x180-precomposed.pngfavicon-16x16.pngfavicon-32x32.pngfavicon-128x128.pngfavicon-256x256.pngmstile-150x150.pngsafari-pinned-tab.svg
Add connect-favicons to your middleware stack before everything else. The whole point here is to serve favicon.ico and apple-touch-icon.png (et al.) quickly, without involving any routing.
In this case, you may have all your site icons, including favicon.ico in /public/img/icons:
app.use(favicons(__dirname + '/public/img/icons'));Now any request to the example.com/favicon.ico or example.com/apple-touch-icon.png will be served by Connect Favicons, reading from the folder you specified.
var http = require('http');
var path = require('path');
var express = require('express');
var favicons = require('connect-favicons');
var app = express();
// Middleware stack
app.use(favicons(__dirname + '/public/img/icons'));
app.use(express.static(path.join(__dirname, '/public')));
http.createServer(app).listen(3000, function(){
console.log("Express server listening on port " + 3000);
});