← Back to questions

TypeError: Cannot read properties of undefined when accessing nested object

javascript·nodejs·debugging·javascriptopen·1d ago·0 views
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 here

The 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.

Your Answer

Sign in to post an answer.

Sign in