1

How do prevent favicon request in Goolge chrome as I am getting 2 requests?

const express= require('express');
const app=express();
const port=3000;
app.use((req , res , next)=>{
    console.log("In the Middleware");
    next();
});
app.use((req , res , next)=>{
    console.log("In the Other Middleware");
    res.send("<h1>Hello From Express</h1>");
});
app.listen(port,()=>{
    console.log('App running at port '+port);
});

What should I do please help?

  • 1
    Several browsers make this request automatically. – doublesharp Nov 07 '19 at 15:20
  • 1
    Possible duplicate of [Why is Chrome searching for my favicon.ico when I serve up a file from ASP.NET MVC?](https://stackoverflow.com/questions/1003350/why-is-chrome-searching-for-my-favicon-ico-when-i-serve-up-a-file-from-asp-net-m) – doublesharp Nov 07 '19 at 15:21
  • How do i prevent this ? this is so annoying while working as beginner , or this is okay to work as this is doing? – Sarwan Nizamani Nov 07 '19 at 15:37
  • Try searching this site: https://stackoverflow.com/a/35408810/1427161 – doublesharp Nov 07 '19 at 15:57
  • This usually isn't a problem if you don't send a response on EVERY possible path like you are doing. That's probably just not a good server design. Instead, configure specific routes for specific paths and then use a default 404 handler that will catch all other routes and send a 404 response for them. Then, the request for the favicon.ico won't end up triggering some action you don't expect. – jfriend00 Nov 07 '19 at 16:15
  • Okay Thank You So Much – Sarwan Nizamani Nov 07 '19 at 16:33

0 Answers0