Express

Hi everyone. It says Since req.params.id is '1’. Why so? Why is it one?

Hello,

req.params.id is '1' because of the URL of the PUT request and because of the route specified in the call to app.put().

In this case, the example request provided is: PUT /monsters/1?name=chimera&age=1. Express matches up this request with your route '/monsters/:id' and does some parsing of the URL because of the included :id

/monsters/1?name=chimera&age=1

Anything after the ? in the URL is accessed through req.query so we can ignore ?name=chimera&age=1 for now.

If your route had been '/monsters/:monsterId' then you’d still be able to access the '1' with req.params.monsterId

1 Like

Oh, didn’t see that number 1 in the path. Thanks.
Can you please remind me how we style text here so it looks like code?

Sure, you can use this option in the style bar:
image

That’s really just a shortcut to adding a block of backticks

1 Like