I recently started working in Node.js and in the app.js file there is this line:
app.use(express.favicon());
Now, how do I set up my own custom favicon.ico?
expressfaviconjavascriptnode.js
I recently started working in Node.js and in the app.js file there is this line:
app.use(express.favicon());
Now, how do I set up my own custom favicon.ico?
Best Answer
In Express 4
Install the favicon middleware and then do:
Or better, using the
path
module:(note that this solution will work in express 3 apps as well)
In Express 3
According to the API,
.favicon
accepts a location parameter:Most of the time, you might want this (as vsync suggested):
Or better yet, use the
path
module (as Druska suggested):Why favicon is better than static
According to the package description:
ETag
based on the contents of the icon, rather than file system properties.Content-Type
.