FreeCodeCamp-APIs and Microservices — Timestamp Microservice Project
Our goal is freeCodeCamp APIs and Microservices certificate. We have to do five project. First one is Timestamp Microservice 🕒🚀
I used Node.Js, Express for my project also cors for the freeCodeCamp tests.
Let’s get start to write our codes 👨💻
We have to handle six conditions for our api.
1-) It should handle a valid date, and return the correct unix timestamp
2-) It should handle a valid date, and return the correct UTC string
3-) It should handle a valid unix date, and return the correct unix timestamp
4-) It should return the expected error message for an invalid date
5-) It should handle an empty date parameter, and return the current time in unix format
6-) It should handle an empty date parameter, and return the current time in UTC format
Our dateString input types are like this formats [2019–12–07],,[ ],[invalid-randomtext].
First of all if our input is an empty value we need to check this condition and create a new Date() variable. Else we need to check input is a dateString or a unixtime. If our input is not empty or valid date types, we’ll set to it is invalid.
I used freeCodeCamp starter index.html file. I think it’s explaining clearly.
Last thing we have to listen request for our app on port 3000. We can check the console if it works properly we can see the force 😉
It’s working. We need to add this url to our projects url …. /api/timestamp/
Output is should be like this format .
Here is the live version >>> https://bdev-fcctimestamp.glitch.me