Skip to content

TypeError: Cannot read property in Nodejs #25

Description

@dcjayasuriya2020

my code:
var firstName = typeof(data.payload.firstName) == 'string' && data.payload.firstName.trim().length >0 ? data.payload.firstName.trim() : false;

but when it runs in git bash, I got the err as :
`$ node index.js
It's listening on 3200 in staging mode
It's listening on 3201 in staging mode
file:///E:/Learn/lib/handlers.js:29
var firstName = typeof(data.payload.firstName) == 'string' &&
data.payload.firstName.trim().length >0 ? data.payload.firstName.trim() : false;
^

TypeError: Cannot read property 'firstName' of undefined
at Object.handlers._users.post (file:///E:/Learn/lib/handlers.js:29:41)
at handlers.users (file:///E:/Learn/lib/handlers.js:16:37)
at IncomingMessage. (file:///E:/Learn/index.js:107:21)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)`

how to resolve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions