I am trying to create a nodeJS/Express site where users are able to create posts. Each post has its own id (consisted of 6 random characters). I want to make it so that when a user enters the URL http://localhost:3000/post/123456/, the user sees HTML on their screen but the id of the post they're trying to see, that means the second parameter in the URL (In this case, 123456) is given to the client.
For example, if the user goes on http://localhost:3000/post/111111/, I want the client to see HTML, but, I want the Javascript on that page to receive that id (111111), either in a variable or in a cookie.
I've tried using express app.get, like this:
app.get("/post/:id", (req, res) => {
req.send(req.params.id)
})
But, obviously that didn't work, since that doesn't send back HTML, but instead sends back a string. Is there any way of doing that, or at least something similar to that?