I have an API with Nodejs/Express which receives input from a form with an option for date as request body.
I am currently sending this format of date YYYY-mm-dd
and have also tried this one too dd/mm/YYYY
but the server crashes when I test in Postman with this error:
UnhandledPromiseRejectionWarning: ValidationError: profile validation failed: experience.0.from: Cast to Date failed for value "2017-14-09" at path
"from"
at new ValidationError (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\error\validation.js:30:11)
at model.Document.invalidate (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\document.js:1957:32)
at EmbeddedDocument.invalidate (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\types\embedded.js:287:19)
The user ideally can input any format of date they desire but how do I receive the input without errors. Is there a proper way to do this? Thanks.