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

Alex Oates
Alex Oates
7,171 Points

'Cannot read property aID of undefined'

On my put request, a 500 error is thrown 'Cannot read property aID of undefined'

Req URL: localhost:3000/questions/9/answers/33/

This is my route for the request

router.put('/:qID/answers/:aID', (res, req) => {
    res.json({ 
        response: `You sent me a PUT request to /answers/${req.params.aID}` ,
        questionId: req.params.qID,
        answerId: req.params.aID,
        body: req.body
    });
});
Alex Oates
Alex Oates
7,171 Points

EDIT: I had placed (res, req) => the wrong way around, changing this to (req, res) => obviously fixes the issue, doh.