Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Tom Elliott
Tom Elliott
4,272 Points

/blog/[name] gives me the full object, not one of the objects within the object

I'm on the Express Basics 'Requests and the request object' video about 7 minutes in, and when I go to a website at /blog/[the name of the blog title] it gives me the entire object (all 3 objects from the posts.json we created) instead of one of the objects. I know logically it should happen as it does in the video, and can't figure out why it's not. Everything has been saved, and we're running it with nodemon so it updates automatically.

1 Answer

Tom Elliott
Tom Elliott
4,272 Points

I figured out the answer to my own question. I had added #1 from the first part of the exercise (:id), and instead of deleting I started a new .get for the second part of the exercise (:title). When I took out #1 I got the correct response.

// #1: app.get('/blog/:id', function(req, res){ res.send(posts); });

// #2: app.get('/blog/:title', function(req, res){ var title = req.params.title; var post = posts[title]; res.send(post); });