I recently completed Stage 0 of the Backend Wizards challenge. The task was to build a RESTful API endpoint that returns my profile information along with a dynamic cat fact from the Cat Facts API.
Goal:
- Create a GET /me endpoint
- Return JSON with my profile, current UTC timestamp, and a dynamic cat fact
- Handle errors gracefully
- Ensure proper formatting for automated grading
My Approach:
- Set up Express.js: Installed express, axios, cors, and morgan for request logging.
- Profile object: Stored email, full name, and stack as a constant.
- Dynamic cat fact: Fetched from Cat Facts API using Axios with a 5-second timeout.
- Error handling: Added fallback in case the API fails.
- Timestamps: Generated ISO 8601 UTC timestamps dynamically on each request.
- CORS and logging: Enabled CORS for public access, used Morgan for request logs.
- Deployment-ready: Prepared for Railway with a proper start script.
Key Learnings:
- How to integrate third-party APIs in real-time
- Handling API failures gracefully
- Returning strictly formatted JSON for automated grading
- Setting up a simple, production-ready Express server
Example Response:
{
"status": "success",
"user": {
"email": "your.email@example.com",
"name": "Your Full Name",
"stack": "Node.js/Express"
},
"timestamp": "2025-10-17T14:25:36.123Z",
"fact": "Cats have five toes on their front paws, but only four toes on their back paws."
}
Snapshots / Testing:
- Local test: http://localhost:3000/me
- Heroku deployed test: https://hng-internship-enoch-stage0-970ab657030f.herokuapp.com/me
Next Steps:
- Stage 1 will expand the backend with database integration and more dynamic endpoints.
This task taught me the importance of combining clean code, proper error handling, and dynamic API consumption while keeping responses predictable and automated-test friendly.
Top comments (0)