I don’t really understand what this Express Yourself machine does.
By clicking “REFRESH EXPRESSIONS” button, what kind of HTTP request is sent?
Unless we know exactly what this app does, following the series of instructions in this unit won’t be educational enough for us to understand how Express.js works…
In this exercise, the const express is declared by requiring from the express module, no brackets. For the getElementById and seedElements, why are they declared with brackets { } ?
In this exercise, the const express is declared by requiring from the express module, no brackets. For the getElementById and seedElements, why are they declared with brackets { } ?
I am completly lost in this excercise, the notation for declaring const { getElementById, seedElements } and params key word, just come out of the blue and don’t make sense of what I learned so far.
By reading the coments here, I kind of get that the const declaration is a way to import in express
There needs to be some more guidance provided to understand what this exercise is trying to achieve. getElementById is JS pointing to item on a webpage - this is not how many APIs are developed and work - and is an added complication when trying to explain that GET methods can call multiple JSON objects or a single JSON object.
I have to agree with my predecessors that this lesson is overcomplicated and some more guidance should have been given in the beginning about what the express yourself machine is and how it works.
To shed some light on the issues many of us are having here:
This line of code is added to make the “express yourself machine” actually work and populates the “expressions” array with 3 emojis. As already explained by @cloud5675760806, it is ES6 syntax for importing two functions with one line of code from the utils folder.
After you have implemented the app.get( ) route for the "/expressions/:id" path, you should start your server in the terminal with node app.js , refresh the webpage on the right hand side so that the express yourself machine is shown, and at the top left of the webpage select GET to test your implemented route. You have to enter an id between 1 and 3 and if implemented correctly, an emoji and its name should be shown and the status code 200 should appear.
@callmej9 It only specifies the name of hydra if you invoke the get request with the path expressions/hydra in this case.
As an example, you can add console.log(req.params) to the function of your app.get() route like this:
This will print the params object for every get request that you perform with the express yourself machine to the terminal and you can observe how it changes.
@codecademy I know that this forum is most of all meant to discuss and find solutions among the users, but please forward this lesson to your content team to revise and improve the explanations.
In the above snippet, is the monsters object missing a ‘name’ property, that is, should ‘hydra’ and ‘dragon’ be values to a name key in their respective objects? Until this point, i haven’t seen any examples of a route matching without a property of the same name. When the text describes wildcards, " For example /monsters/:id will match both /monsters/1 and /monsters/45", I assume 1 and 45 are the values to ‘id’ keys. The Express documentation appears to confirm my thoughts about the wildcard/key paring, but I could be interpreting it incorrectly.
Because you specified your route param as :name'/monsters/:name', when a request is sent with the lets’s call it “argument” hydra, or whatever string '/monsters/hydra' or '/monsters/dalek', said “argument” will be matched with the key :name in your params object.
Then you can access in the monsters object the property with the name of your argument (hydra or whatever), by using the aliasreq.params.name where the argument is stored.
At least that’s how I interpreted it. It really is kind of confusing and poorly explained, I hope my rambling about it helped.
being used twice in one file ??? Lesson 4 & 6 so far i’ve seen. I have never seen this before, and surely if it was a bug somebody would have spotted it before now