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 Build a REST API With Express Building API Routes in Express Building the Answer Routes

Peter Gess
Peter Gess
16,553 Points

Where is the data residing?

In the paths that are passed into the first parameter within these routes ("/:qD/answers/:aID"), where is this data actually being held?

Jamie Carter
seal-mask
.a{fill-rule:evenodd;}techdegree
Jamie Carter
Front End Web Development Techdegree Student 12,096 Points

Data is passed into your api route vie the res parameter.

Depending on your api call get, or post it will be stored in different places.

Sometimes its a good idea to use console.log(res) and explore the res object.

Often the data is held in res.body. (post request) or res.query (get).

Unless you use the res.body/.query inside your function or store the data to a new variable the data will be ignored

3 Answers

At this stage in the project, the data is not being stored. When you make a POST or PUT request, the router sends back the json response with the hard coded string (or dynamic :qID values). It looks like Stage 3 of the project is setting up the data stores in Mongo. You may want to check out the Mongo Basics course if you have not already gone through that, as well.

Peter Gess
Peter Gess
16,553 Points

Ok, I understand that there is res object that holds the data. However, when in development using a localhost where is it held before the database is set up?

Peter Gess
Peter Gess
16,553 Points

Thanks for the clarification!