Nodejs Timestamp Microservice

Nodejs Timestamp Microservice
0

#1

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


#2

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


#3

Sorry for making this confusion! I updated my question.


#4

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));

#5

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


#6

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


#7

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


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

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


#9

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


#10

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.


#11

thanks man! I understand now!