In this video we are going to learn about how to create custom 404 page.
by default when we just to go any wrong URL which is not exist like /xyz.
It will show a message Cannot GET /xyz.
Now I am going to create a custom 404 page.
So first of all create a new file inside the views folder.
Go to the views folder and here just create new file.
Lets say file name is 404.ejs.
Inside this file write the following code.
Now go to the index.js file and here just write.
Now save all and lets check.
So goto the browser and any url which not exist.
So just type /sdfsdfsd.
and you can see here the custom 404 error page.
So in this way you can create a custom 404 error page in nodejs.
by default when we just to go any wrong URL which is not exist like /xyz.
It will show a message Cannot GET /xyz.
Now I am going to create a custom 404 page.
So first of all create a new file inside the views folder.
Go to the views folder and here just create new file.
Lets say file name is 404.ejs.
Inside this file write the following code.
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>404</title>
</head>
<body>
<h1>404</h1>
<p>The page you are looking for is not available.</p>
</body>
</html>
Now go to the index.js file and here just write.
app.use(function(req,res,next){
res.status(404)render('404');
});
Now save all and lets check.
So goto the browser and any url which not exist.
So just type /sdfsdfsd.
and you can see here the custom 404 error page.
So in this way you can create a custom 404 error page in nodejs.