You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

serve-favicon

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve-favicon

favicon serving middleware with caching

2.5.1
latest
Source
npmnpm
Version published
Weekly downloads
2.5M
-7.95%
Maintainers
2
Weekly downloads
 
Created

What is serve-favicon?

The serve-favicon npm package is a middleware for serving a favicon, a small icon associated with a particular website or web page. It is commonly used in Node.js applications to define and serve the favicon efficiently, handling caching and other concerns.

What are serve-favicon's main functionalities?

Serving a favicon

This code sample demonstrates how to use serve-favicon to serve a favicon from a specified path in an Express.js application. The favicon.ico file is located in the 'public' directory, and the middleware is set up to serve it.

const express = require('express');
const favicon = require('serve-favicon');
const path = require('path');

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

app.listen(3000);

Caching

This code sample shows how to set a cache-control max-age directive for the favicon, which tells browsers to cache the favicon for a specified amount of time (in this case, 30 days).

const express = require('express');
const favicon = require('serve-favicon');
const path = require('path');

const app = express();
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'), { maxAge: 2592000000 }));

app.listen(3000);

Other packages similar to serve-favicon

Keywords

express

FAQs

Package last updated on 10 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts