如何在快递中设置自定义图标? [英] How to set custom favicon in Express?
本文介绍了如何在快递中设置自定义图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近开始在Node.js中工作,在app.js文件中有这样的一行:
I recently started working in Node.js and in the app.js file there is this line:
app.use(express.favicon());
现在,如何设置自己的自定义favicon.ico?
Now, how do I set up my own custom favicon.ico?
推荐答案
Express 4
安装 favicon中间件,然后执行以下操作:
In Express 4
Install the favicon middleware and then do:
var favicon = require('serve-favicon');
app.use(favicon(__dirname + '/public/images/favicon.ico'));
或者更好的是,使用路径
app.use(favicon(path.join(__dirname,'public','images','favicon.ico')));
(请注意,此解决方案也适用于快速3应用程序)
(note that this solution will work in express 3 apps as well)
According to the API, .favicon
accepts a location parameter:
app.use(express.favicon("public/images/favicon.ico"));
大多数情况下,您可能希望(如vsync建议):
Most of the time, you might want this (as vsync suggested):
app.use(express.favicon(__dirname + '/public/images/favicon.ico'));
或者更好的是,使用路径
(如Druska所建议的):
Or better yet, use the path
module (as Druska suggested):
app.use(express.favicon(path.join(__dirname, 'public','images','favicon.ico')));
这篇关于如何在快递中设置自定义图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文