How to set custom favicon in Express?

前端 未结 14 1893
星月不相逢
星月不相逢 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:13

    step 0: add below code to app.js or index.js

    app.use("/favicon.ico", express.static('public/favicon.ico'));

    step 1: download icon from here https://icons8.com/ or create your own
    step 2: go to https://www.favicongenerator.com/
    step 3: upload the downloaded icon.png file > set 16px > create favicon > download
    step 4: go to downloads folder, you'll find [.ico file], rename it as favicon.ico
    step 5: copy favicon.ico in public directory you created
    step 6: add below code to your .pug file under head tag, below title tag

    
    

    step 7: save > restart server > close browser > reopen browser > favicon appears

    NOTE: you can use name other than favicon,
                but make sure you change the name in code and in the public folder.

提交回复
热议问题