Simple Express.js microservice that converts dates to Unix time (milliseconds) and UTC string. Built as part of the freeCodeCamp Back End Development and APIs curriculum.
📅 This part is a good challenge for learning about date/time in JavaScript
- Accepts either an ISO-8601 date string (e.g.,
2015-12-25
) or a Unix timestamp in milliseconds (e.g.,1451001600000
). - Returns a JSON response with both
unix
andutc
representations, or an error payload when the input is invalid. - If no date is provided, returns the current timestamp.
- Input validation with clear error shape:
{ "error": "Invalid Date" }
- Supports ISO date strings and numeric Unix milliseconds
- Single endpoint with optional parameter for simplicity
- Node.js >= 22 (tested with Node 22)
- express
- dotenv ( loads environment variables )
- cors
# Clone repository
git clone https://github.com/HGiang01/timestamp-microservice.git
cd timestamp-microservice
# Install dependencies
npm install
# Start the server
npm start
# The app listens on PORT (default 3000)
# Visit http://localhost:3000
PORT
: Port the HTTP server listens on (default:3000
).- See
sample.env
for an example value. Note: environment variables must be provided by your shell or process manager; no.env
loader is bundled.
Base URL (local): http://localhost:3000
-
GET /api
- Returns the current time in both Unix milliseconds and UTC.
-
GET /api/:date
:date
can be either an ISO-8601 date string (e.g.,2015-12-25
) or a Unix timestamp in milliseconds (e.g.,1451001600000
).- Responses:
- Success:
{ "unix": 1451001600000, "utc": "Fri, 25 Dec 2015 00:00:00 GMT" }
- Invalid input:
{ "error": "Invalid Date" }
- Success:
GET /api/2015-12-25
→{ "unix": 1451001600000, "utc": "Fri, 25 Dec 2015 00:00:00 GMT" }
GET /api/1451001600000
→{ "unix": 1451001600000, "utc": "Fri, 25 Dec 2015 00:00:00 GMT" }
GET /api/this-is-not-a-date
→{ "error": "Invalid Date" }
\rGET /api
→ current time
MIT