← Back to questions
TypeError: Cannot read properties of undefined when accessing nested object
0
I keep getting this error in my Node.js app:
TypeError: Cannot read properties of undefined (reading "name")My code looks like:
const user = await db.findOne({ id: userId })
console.log(user.profile.name) // crashes hereThe user exists in the database but sometimes this crashes. What is happening and how do I safely access nested properties?
Asked by @lTVzGIA0E5TJPPnBzEue
0 Answers
No answers yet. Be the first to answer below.