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 REST APIs with Express Getting to Know REST APIs GET a Quote, GET all Quotes

Vlad Tanasie
Vlad Tanasie
7,201 Points

Cannot read property 'find' of undefined

When i try to go to the a single quote with any id i get this: Cannot read property 'find' of undefined Also the browser console logs an error that sais that it refused to load the url because it violates Content Security Policy directive and it refuses to load in image for some reason

2 Answers

codingchewie
codingchewie
8,764 Points

If you've brought in the data.json file in app.js:

const data = require('./data')

you're getting that error because the data.json and the find line do not match. Example, in the supplied files the data.json uses records but in the video at to the bottom of the file after the listen it uses quotes.

To resolve the error of Cannot read property 'find' of undefined change the data.json file from records to quotes or modify the find line to:

const quote = data.records.find((quote) => quote.id == req.params.id)
Boon Kiat Seah
Boon Kiat Seah
66,664 Points

Can you show your code here so that the community can better help you in debugging?