How to set custom favicon in Express?

前端 未结 14 1886
星月不相逢
星月不相逢 2020-12-12 12:49

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 cu

相关标签:
14条回答
  • 2020-12-12 13:17

    Install express-favicon middleware:

    npm install express-favicon --save
    

    Use it like this:

    const favicon = require('express-favicon');
    app.use(favicon(__dirname + 'favicon.ico'));
    
    0 讨论(0)
  • 2020-12-12 13:19

    The code listed below works:

    var favicon = require('serve-favicon');
    
    app.use(favicon(__dirname + '/public/images/favicon.ico'));
    

    Just make sure to refresh your browser or clear your cache.

    0 讨论(0)
提交回复
热议问题