Project URL: https://404-example.glitch.me
in the past month, i’ve answered at least 3 questions about a custom 404 page. i have made a simple example and created a glitch for it so you can see how it works.
code:
create a package.json
file. this will switch your site from static to server and get rid of the 24/7 uptime provided by glitch. code:
{
"name": "defresh",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
},
"engines": {
"node": "8.x"
}
}
and a server.js
file with something like this:
var express = require("express");
var app = express();
app.use(express.static(__dirname));
app.use((req, res) => {
res.status(404).sendFile(__dirname + "/404.html");
});
app.listen(8080);
that’s all. and you have to make the 404.html
file, create the 404 page, and then you’re done!