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

Viewed 138

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.

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.

Related