14 Replies
I'm pretty sure that the error is in the line immidiately after the
if condition:
That's what I thought, but changing it to [2] now givs me the "User not found" message
🤷

Wait, no, that's wrong. Shit
You're right, since the url is actually
/api/users/3. That first / makes it ["","api", "users", "3"].
So index 3 is correctSeems to be working now.. again, not entirely sure why it suddenly now works, I just changed the 2 back to a 3, saved, went back into postman and ran it again
doesn't seem to work every time I change it.. is there a cooldown or request limit in postman I'm not seeing perhaps?


What I'd do:
Well shoot, you fixed it before I could tell you to add console logs :p
Are you following a course? Is that where you're getting the code?
Yeah it's Traversy media "node js crash course" from 1 year ago
just a youtube vid
Small rant, but a more "correct" version of REST would be to have the user ID (or any other variable) be a query param and not part of the URL itself. But that's because I've been taught more about what REST really is and not what people want it to be. The creator of the REST "archetechture" is very unhappy with what is being called "REST" but is acutally just SOAP using JSON :p
That way,
if query param get one item, else do other default action. But since you're following a course you should do what the teacher teachesMaybe he'll show that in a bit, to be fair it has gone from very basic to more advanced throughout
this is just nodejs though, no express or anything
I highly doubt it. 99% of anyone teaching anything API-related uses hardcoded URL wildcards and totally ignore query params. Makes me sad
That I know. And I'm happy to see that, at least. "Let's learn Nodejs! Step 1: NPM install 16 packages!" is not how one learns Nodejs, it's how one learns to install packages :p
haha yeah, all we've done is nodemon
I do like traversy, he doesn't tend to overcomplicate things
And that's not so much a package you use in prod, it's just so you don't have to restart your server all the time
I hope I can get to that stage one day soon. Provide a well-written Nodejs course. Teach the language and not the package ecosystem
Anyway, I'll get off my soapbox and let you get back to Brad! Good luck on your Nodejs journey! Feel free to ping me in any question thread you make 😁
Thanks Beck!
