Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date type object gets converted into String while returning using res.json

I have a date object, lets say var myDate = new Date().

Now when I am returning it using res.json({msg: {myDate: myDate}}) the myDate object gets converted into string.I want that the type of myDate should persist. I am using mongoose ODM and express.

like image 961
amanpurohit Avatar asked Oct 25 '25 14:10

amanpurohit


1 Answers

JSON doesn't have a date type, which means you have to convert it to date when it reaches the front-end. The JSON spec is here.

like image 159
Mika Sundland Avatar answered Oct 28 '25 04:10

Mika Sundland