All Projects → expressjs → Serve Favicon

expressjs / Serve Favicon

Licence: mit
favicon serving middleware

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Serve Favicon

Cors
Node.js CORS middleware
Stars: ✭ 5,252 (+796.25%)
Mutual labels:  middleware, expressjs
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (-55.12%)
Mutual labels:  middleware, expressjs
Compression
Node.js compression middleware
Stars: ✭ 2,506 (+327.65%)
Mutual labels:  middleware, expressjs
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-76.28%)
Mutual labels:  middleware, expressjs
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+3583.79%)
Mutual labels:  middleware, expressjs
Csurf
CSRF token middleware
Stars: ✭ 2,183 (+272.53%)
Mutual labels:  middleware, expressjs
deepword
Web editor based on Monaco
Stars: ✭ 25 (-95.73%)
Mutual labels:  middleware, expressjs
Serve Static
Serve static files
Stars: ✭ 1,217 (+107.68%)
Mutual labels:  middleware, expressjs
Express Openapi Validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
Stars: ✭ 436 (-25.6%)
Mutual labels:  middleware, expressjs
Serve Index
Serve directory listings
Stars: ✭ 360 (-38.57%)
Mutual labels:  middleware, expressjs
Cookie Parser
Parse HTTP request cookies
Stars: ✭ 1,683 (+187.2%)
Mutual labels:  middleware, expressjs
Swagger Express Middleware
Swagger 2.0 middlware and mocks for Express.js
Stars: ✭ 543 (-7.34%)
Mutual labels:  middleware, expressjs
Express Recaptcha
Implementation of google recaptcha v2 & V3 solutions for express.js
Stars: ✭ 104 (-82.25%)
Mutual labels:  middleware, expressjs
Body Parser
Node.js body parsing middleware
Stars: ✭ 4,962 (+746.76%)
Mutual labels:  middleware, expressjs
Redux Favicon
Redux middleware that displays colourful notification badges in the favicon area.
Stars: ✭ 103 (-82.42%)
Mutual labels:  middleware, favicon
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (-97.1%)
Mutual labels:  middleware, expressjs
Vhost
virtual domain hosting
Stars: ✭ 686 (+17.06%)
Mutual labels:  middleware, expressjs
Cookie Session
Simple cookie-based session middleware
Stars: ✭ 928 (+58.36%)
Mutual labels:  middleware, expressjs
Express Status Monitor
🚀 Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev
Stars: ✭ 3,302 (+463.48%)
Mutual labels:  middleware, expressjs
Kraken Js
An express-based Node.js web application bootstrapping module.
Stars: ✭ 4,938 (+742.66%)
Mutual labels:  middleware, expressjs

serve-favicon

NPM Version NPM Downloads Linux Build Windows Build Test Coverage

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?

  • User agents request favicon.ico frequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.
  • This module caches the icon in memory to improve performance by skipping disk access.
  • This module provides an ETag based on the contents of the icon, rather than file system properties.
  • This module will serve with the most compatible 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.

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ 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 year. 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 = require('express')
var favicon = require('serve-favicon')
var path = require('path')

var app = express()
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))

// Add your routes here, etc.

app.listen(3000)

connect

var connect = require('connect')
var favicon = require('serve-favicon')
var path = require('path')

var app = connect()
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))

// Add your middleware here, etc.

app.listen(3000)

vanilla http server

This middleware can be used anywhere, even outside express/connect. It takes req, res, and callback.

var http = require('http')
var favicon = require('serve-favicon')
var finalhandler = require('finalhandler')
var path = require('path')

var _favicon = favicon(path.join(__dirname, 'public', 'favicon.ico'))

var server = http.createServer(function onRequest (req, res) {
  var done = finalhandler(req, res)

  _favicon(req, res, function onNext (err) {
    if (err) return done(err)

    // continue to process the request here, etc.

    res.statusCode = 404
    res.end('oops')
  })
})

server.listen(3000)

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].