Ask coding questions

← Back to all posts
How can we remove .html from our pages?
Xenity (9)

So me and @A1PHA1, want to remove .html from our pages. We are using a node server but can't figure out how to do it, we have tried things but they haven't worked. Any help is appreciated (we also want to link our 404 page, link to repl:

Answered by BrysonVan1 (11) [earned 5 cycles]
View Answer
BrysonVan1 (11)

To remove the .html from your pages, move your html files out of the public folder and into another folder (I like using one called views but its up to you). Then, create routes to each one of your pages using app.get("/route", (req, res) => {res.sendFile(__dirname + "/views/pagetoshow.html")})

Xenity (9)

@BrysonVan1 Thanks! it works, but how do we link our 404 page?

BrysonVan1 (11)

@Xenity At the bottom of your code (but above server.listen), do the same app.get thing but have * as the route. Make sure this is at the bottom of your code or literally all of your pages will return 404.