Search code examples
node.jserror-handlinghttp-status-code-404renderdefault

How to render the browser error 404 with nodejs




It may sound really stupid but is it possible to render the default browser error page with NodeJS?

All I found on the internet, is to make personalized content (a simple text <res.send('Page not found')>, a blank page <res.end()> or a custom page) but not the default page of the browser. And if I do not return a response, the browser waits until timeout.


Solution

  • It seems Firefox doesn't have a default 404 page (despite it has an unavailable page when accessing a random non-existing website, which is different error).

    Assuming you're using Express, the simple response code that you may have seen :

    res.status(404).end();
    

    makes Chrome (Chromium 107.0.5304.87) displaying its own error page as expected, but not firefox (107).

    Source is a bit outdated, but seems still relevant.