Question:
I am doing a practise project in Node/Express.My server.js looks like this:
localhost:3000/envelopes/groceries?name=taxes
it should change the name of the envelope from “groceries” to “taxes”. For some reason req.params.name
is “undefined” and I have error “TypeError: Cannot set properties of undefined (setting ‘name’)”. When I had it all in one file, without routers, it worked perfectly. Any ideas?Answer:
I think you need to add{ mergeParams: true }
to make the params available, because you use another router file then where you define the route.See Express docs
If you have better answer, please add a comment about this, thank you!