6

I'm currently running a simple express.js example just trying to get favicons working. Everything works fine locally but when I upload it to my production server it just shows the default favicon. I've tried clearing the cache but the production server favicon seems to not want to show up. I'm running everything on iisnode on a windows 2008 aws server.

Anyone know what the problem might be?

var express  = require('express');
var app      = express();
var port     = process.env.PORT || 3000;
var bodyParser = require('body-parser');

//for favicon
var favicon = require('serve-favicon');



app.configure(function() {
  app.use(express.favicon(__dirname + '/views/icons/favicon.ico'));
  app.use(express.static(__dirname, 'views'));
});


app.listen(port);
console.log("full path is: " + (__dirname + '/views/icons/favicon.ico'));
console.log('The magic happens on port ' + port);
David
  • 105
  • 1
  • 9
  • There is a similar post here: http://stackoverflow.com/questions/11658035/unable-to-change-favicon-with-express-js?rq=1 – wahiddudin Jun 23 '14 at 01:17
  • It looks like you require('serve-favicon') but you're using express.favicon() instead. Note that if you're using express 4, express.favicon() won't be available – Ben Jun 23 '14 at 01:46
  • Also `app.configure()` no longer exists in Express 4. – mscdex Jun 23 '14 at 02:01

3 Answers3

5

Install the favicon middleware and then do:

var favicon = require('serve-favicon');

app.use(favicon(__dirname + '/public/images/favicon.ico'));

Or better, using the path module:

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

(note that this solution will work in express 3 apps as well)

Removed in Express 4 : app.configure()

app.configure() is no longer available. Refer to this for more info.

steampowered
  • 11,809
  • 12
  • 78
  • 98
Okky
  • 10,338
  • 15
  • 75
  • 122
2

sometimes it take longer time to show up in browser. Try to clean cache or try another browser and refresh multiple time.

kamal pandey
  • 147
  • 1
  • 4
0

Install dependencies serve-favicon and path from npm, and update index.js accordingly.

//import packages
var favicon = require('serve-favicon'), path = require("path");
//use favicon icon path to access in application.
app.use(favicon(path.join(__dirname+'/favicon.ico')));

Refresh the browser to reflect the favicon.

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90