I played with your repo code and made some changes to see if I can serve my favicon or not. I found out some weird stuff:
favicon service is complicated and mysterious (my point)- Chrome used to have a bug, or maybe still be related to favicon (Google, please have a lot of results)
- Looks like
favicon browser caches, forced update, and various methods used to get the new / updated favicon browser, see here - I found that after the Chrome browser serves favicon, there is no longer a favicon request in a subsequent request. Until you change the
href of favicon in your html file and force the browser to make a new request.
I copied the bit / snippets of your code to reproduce the problem and got it working. I decided to use favicon in different ways, as shown below:
server.js
if(req.url.match("/requestFavicon") ){ var img = fs.readFileSync('public/favicon.ico'); res.writeHead(200, {'Content-Type': 'image/x-icon' }); res.end(img, 'binary'); }
index.html
<link rel="shortcut icon" type="image/x-icon" href="/requestFavicon"/>
Made nodemon server.js and used the Chrome browser to request http://192.168.1.18:8080 . terminal showed the following:
GET request for / GET request for /requestFavicon
And favicon.ico (the tiny .ico car taken from here ) displayed in the browser, see below:

After the favicon was displayed above, any subsequent http://192.1668.18:8080 did not issue a request for favicon , but displayed only the following request in the nodejs terminal
GET request for /
Likewise, there is no favicon related query on the developer's developer network tab.
At this point, I assumed that the browser cached it and did not request at all, because it already has it. So I searched googled and stumbled upon this SO question to force update favicon request. So change favicon href to index.html (and server.js ) and try again
<link rel="shortcut icon" type="image/x-icon" href="/updatedRequestFavicon"/>
Now retry accessing http://192.168.1.18:8080 and look at the nodejs terminal as well as the Chrome developer console, and I get the following:
GET request for / GET request for /UpdatedRequestFavicon

Now I want to completely change favicon and put in a new one. I added this updated server.js and updated the browser. Surprisingly, the console log in nodejs (for the new favicon ), no request in the browser to the developers of the newtork console tools (therefore, it then served as a cached value).
To get the browser to get a new favicon , I want to change the href in favicon in index.html and update server.js new href, and then see if Brwoser is forcibly requested for the updated icon or continue to use the cached one.
<link rel="shortcut icon" type="image/x-icon" href="/NewFavicon"/> if(req.url.match("/NewFavicon") ){ var img = fs.readFileSync('public/favicon_new.ico'); res.writeHead(200, {'Content-Type': 'image/x-icon' }); res.end(img, 'binary'); }
Modified. The changes are reloaded by nodemon, the browser is updated, and here is the result:
GET request for / GET request for /NewFavicon

Your problem may be related to
- The browser already has a cached icon, so it does not request it
- You are not using the icon correctly in server.js
- Something else
If you want to test my code feel free, here is server.js
var http = require('http'); var fs = require('fs'); var path = require('path'); var server = http.createServer(function(req, res) { // Log req Method console.log(`${req.method} request for ${req.url}`); //res.writeHead(200); //res.end('index.html'); // Serve html, js, css and img if ( req.url === "/" ){ fs.readFile("index.html", "UTF-8", function(err, html){ res.writeHead(200, {"Content-Type": "text/html"}); res.end(html); }); } if(req.url.match("/NewFavicon") ){ console.log('Request for favicon.ico'); var img = fs.readFileSync('public/favicon_new.ico'); res.writeHead(200, {'Content-Type': 'image/x-icon' }); res.end(img, 'binary'); //var icoPath = path.join(__dirname, 'public', req.url); //var fileStream = fs.createReadStream(icoPath, "base64"); //res.writeHead(200, {"Content-Type": "image/x-icon"}); //fileStream.pipe(res); } }); server.listen(8080);
Here is index.html
<!DOCTYPE html> <html> <head> <title>nodeCAST</title> <link rel="shortcut icon" type="image/x-icon" href="/NewFavicon"/> </head> <body> <p>I am the index.html</p> </body> </html>
I put favicon.ico in the / public directory. Good luck.
EDIT
Tested with Chrome browser version 47.0.2526.111 m
Node v4.2.4