π Backend Stage 0: Building a Dynamic Profile API with Node.js & Express
Hey everyone π, I'm Trayshmhirk, and this is my submission for the HNG 13 Backend Stage 0 Task β where we were asked to build a simple RESTful API endpoint that returns our profile information along with a dynamic cat fact fetched from the Cat Facts API. π±
π§© Task Overview
The goal was to create a GET /me endpoint that:
- Returns a JSON response containing:
- My name, email, and backend stack
- A timestamp (in ISO 8601 format)
- A random cat fact fetched from an external API
- Uses best practices for clean, maintainable backend code
- Handles API errors gracefully
- Is hosted online (I used Railway π)
βοΈ Tech Stack
For this task, I used:
- Node.js β JavaScript runtime environment
- Express.js β Web framework for building APIs
- Axios β To fetch data from the Cat Facts API
- CORS β To allow external access to the endpoint
ποΈ How I Built It
- Project setup
npm init -y
npm install express axios cors
- Created folder structure
src/
βββ app.js # Express setup
βββ routes/
β βββ profile.js # /me route logic
βββ services/
βββ cat-facts.js # External API integration
Integrated the Cat Facts API
I used Axios to fetch a random fact from the endpointhttps://catfact.ninja/fact
.
If the request fails (e.g., timeout or API down), I return a friendly fallback message like:
"Could not fetch cat fact at the moment."
Built the
/me
route
The route responds with this structure:
{
"status": "success",
"user": {
"email": "harlex.mikkey@gmail.com",
"name": "Micheal Osunbajo",
"stack": "Node.js/Express"
},
"timestamp": "2025-10-17T14:23:45.678Z",
"fact": "Cats have over 20 vocalizations, including the purr, meow, and chirp."
}
- Deployment on Railway I deployed the API to Railway, which automatically detects Node.js projects and assigns a public URL.
Live Endpoint:
π https://tray-stage-zero-backend-task-production.up.railway.app/me
π§ What I Learned
- How to build and structure a simple Express.js API from scratch
- How to make and handle external API requests using Axios
- How to properly return JSON responses in RESTful APIs
- How to deploy a Node.js app to Railway
- The importance of clear README documentation and error handling
This task was a great refresher on backend fundamentals and a perfect warm-up for the upcoming stages. π₯
π§Ύ GitHub Repository
π Repository: https://github.com/Trayshmhirk/tray-stage-zero-backend-task.git
π Final Thoughts
Even though the task was small, I treated it like a real-world microservice β clean folder structure, graceful error handling, and proper documentation.
"Start small, but build like a pro." πͺ
Author: Micheal Osunbajo
π§ harlex.mikkey@gmail.com
π» Stack: Node.js / Express
Cat facts provided by Cat Facts API
Top comments (0)