Solution 1 :

we are simply responding by rendering the exact page as before (whats the point in that)

There is no point, but its looks like a tutorial designed to demonstrate basic principles and not be a practical and useful thing.

What is confusing me about this code is that it is saying we are getting a req from the thanks.html which has not been made yet.

The first argument of app.post or app.get is the path that should appear in the URL that the browser is requesting from the server.

This is not a file name.

The response is determined by the code in the function that is the second argument. That’s not a file unless the code explicitly reads a file.

res.render("thanks", {data}); tells Express to use a template called thanks (and you should have previously configured a template engine) which gets passes the data from the request.

If you haven’t make a thanks template, then requests for /thanks.html are probably just going to cause the server to throw an error.

Problem :

I have been doing coding lessons in my spare time and there is a slight confusion with some pieces of the code:

  • The first one is the action attribute in HTML
  • The second one is this piece of code:

    app.get("/", (req, res) =>// The / is a shortcut for index.html
    {
        res.render(index);//
    }); 
    

the thing that is confusing me about this is that index.html is is the req part of the function and in this function we are simply responding by rendering the exact page as before (whats the point in that)

  • the third and final confusion is to do with this piece of code here:

    app.post("/thanks.html", (req, res) =>
    {
        data = [];
        data.push(req.body);
        res.render("thanks", {data});
    }
    

What is confusing me about this code is that it is saying we are getting a req from the thanks.html which has not been made yet. It gets made when the res.render displays the thanks.html page.

Comments

Comment posted by The_Indestructible

Thank you for helping me to edit it!

Comment posted by The_Indestructible

Ok thanks, that thing with no point is very strange because I have looked at another on of their tutorials and they use it again

By