Skip to content

Where does node search for /favicon.ico ? #52019

Closed Answered by atlowChemi
digimeas asked this question in General
Discussion options

You must be logged in to vote

Node can't find '/favicon.ico' because, where is '/'?

This is the root route of the server.
Node doesn't automatically handle such an endpoint if not explicitly defined, so the endpoint would just "freeze" in pending state until the timeout. This means you need to explicitly handle this endpoint.

Here is an example for handling such an endpoint using http.createServer

const { createServer } = require('node:http');
const { join } = require('path');
const fs = require('fs');
const url = require('url');

// Location of your favicon in the filesystem.
const FAVICON = join(__dirname, 'public', 'favicon.ico');

const server = createServer(function(req, res) {
  const pathname = url.parse(req.url

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by digimeas
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants