Error screens for sites?


#1

Is there a way I can make error screens if someone goes to an invalid extensions (e.g., https://www.support.glitch.com/lolxdlmnolmaogg => “Error 404”)?


#2

You would put an error handler after all of your other handlers that looks something like this:

app.use(function(req, res, next){
  res.status(404);
  res.sendFile(__dirname + '/views/404.html')
});

#3

Uh, I’m not the best at Express and I tried this using a regular website on glitch and would always get the error 404 even if the page existed…


#4

If you’re working with a plain website in Glitch, you don’t have control over that. You’ll get a generic 404 page. If you create a node app, then you can do as I suggested.

What’s your project name? What page are you trying to hit that fails? What’s the exact error message?