FreeCodeCamp-APIs and Microservices — Timestamp Microservice Project

FreeCodeCamp

Our goal is freeCodeCamp APIs and Microservices certificate. We have to do five project. First one is Timestamp Microservice 🕒🚀

I used freeCodeCamp Glitch boilerplate project. Here is a starter link.

package.json

I used Node.Js, Express for my project also cors for the freeCodeCamp tests.

Let’s get start to write our codes 👨‍💻

We have got one javascript file called as a server.js for the app run. First thing to do we need call packages to server.js file and create an Express application.

Call the Packages and Create an Express Application

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],[1575741823145],[ ],[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.

After that we need to shows our index.html file. We used our public(style,javascript) folder and render the index.html file.

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 .

It’s my birthday 👅

Here is the live version >>> https://bdev-fcctimestamp.glitch.me

Full Stack Developer👨🏻‍💻 Camper 🏕️