Nodejs Timestamp Microservice

Hello campers!
i am trying to represent my answers in pretty format, like this:

{ 

"unix": 6312872264587826,

"natural": "december 16, 202016" 
}

I tried using require('pretty-format') and also JSON.justify() but still it yeilds answers like this:

{ "unix": 6312872264587826, "natural": "december 16, 202016" }
Can you please help me through this?
code in github

sorry if I didn’t get your question correctly. to work with timestamps in node js use moment.js
here is how you can show the current date in moment js.

moment().format(“MMM Do YY”); // Feb 19th 18

Sorry for making this confusion! I updated my question.

You can’t format JSON for the client. pretty-format is meant to format console output, and if that’s what you’re trying to accomplish, then you simply call the function:

var prettyFormat = require('pretty-format');

console.log(prettyFormat(somJSON));

I am trying to do for response.end()… not for console

And like I said, you cannot format the JSON for clients. They have to do that themselves.

Can you please 0:40 time of fcc challenge ? If I don’t format it how do they expect that kinda of output?

{ "unix": 6312872264587826, "natural": "december 16, 202016" }

If the times were correct, this format would be accepted. You are not expected to format the JSON.

but I want to present it like formatted JSON. How do I do that?

If you use response.json instead of response.end you’ll send a JSON formatted string. You can write a front-end web app that consumes your API, which you can use to display the data however you want for anyone visiting your app. Other than that, there’s nothing you can do. If I make a request to your server, you cannot format the response for me.

1 Like

thanks man! I understand now!

1 Like