How to set custom favicon in Express?

Sometimes, we want to set custom favicon in Express.

In this article, we’ll look at how to set custom favicon in Express.

How to set custom favicon in Express?

To set custom favicon in Express, we can use the server-favicon package.

To install it, we run

npm i server-favicon

Then we use it by writing

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

//...

app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));

to call app.use with the middleware returned by favicon.

We call favicon with the path to the favicon.

Conclusion

To set custom favicon in Express, we can use the server-favicon package.