https://github.com/captaincluster/timestamp-microservice
The first project for the "Back End Development and APIs" course provided by FreeCodeCamp.
https://github.com/captaincluster/timestamp-microservice
backend expressjs freecodecamp freecodecamp-project microservice
Last synced: 12 months ago
JSON representation
The first project for the "Back End Development and APIs" course provided by FreeCodeCamp.
- Host: GitHub
- URL: https://github.com/captaincluster/timestamp-microservice
- Owner: CaptainCluster
- Archived: true
- Created: 2024-05-05T14:33:52.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-05T15:06:23.000Z (almost 2 years ago)
- Last Synced: 2025-02-20T12:47:03.801Z (about 1 year ago)
- Topics: backend, expressjs, freecodecamp, freecodecamp-project, microservice
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Timestamp Microservice

Timestamp Microservice is a simple **ExpressJS** project for the FreeCodeCamp course **Back End Development and APIs**. The user gives a date as a parameter in a request and receives a JSON file with the date in **unix** and **utc** formats.
🙏 Credits
---

Everything not written by me has been cloned from [this GitHub repository](https://github.com/freeCodeCamp/boilerplate-project-timestamp/).
Here is the solution I wrote for this project:
```
app.get("/api/:date", function(req, res)
{
let date = req.params.date;
//Unix type can be recognized as' a number
if(!isNaN(Number(date)))
{
return res.json({
unix: Number(date),
utc: new Date(Number(date)).toUTCString()
});
}
// If the date is not in numeric form, it is expected to be of
// type string. Checking whether it is valid or not...
if(new Date(date).toUTCString() == "Invalid Date")
{
return res.json({
error: "Invalid Date"
});
}
// A valid string date will be handled now, as an invalid one
// would have triggered a return command.
return res.json({
unix: new Date(date).getTime(),
utc: new Date(date).toUTCString()
});
});
```