-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property in Nodejs #25
Comments
i don't see any syntax error with that. I think double check with how you called the function handlers._users.post and also make sure that payload is being supplied in the index.js just as follows: |
thanx @MakMoinee Here is how Handlers user post function was given:
|
Are you having this error during running ? or during triggering it via postman? |
try replace the `
} |
yes exactly, when triggering via POSTMAN, not on running... I tried as per ur guide...still the same err:
|
I now know why you're getting that error: `var chosenHandler = typeof(router[trimmedPath]) !== 'undefined' ? router[trimmedPath]: handlers.notfound;
It seems that you got the wrong spelling the payload. it must be payload not payloads |
ABSOLUTELY Wow! But why or what made 'payload' or 'payloads'... what is the science behind it? |
This is the usual array object. When referencing to a key that its not within the object's key then you will end up having those errors. It means that when you have it as payloads from the object you passed on the handlers then in the handlers you'll probably use data.payloads |
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?
The text was updated successfully, but these errors were encountered: