During the HNG Internship (Stage 0), I built a dynamic RESTful API that integrates with an external service, handles errors gracefully, and returns real-time data using Node.js and Express.
π Live Demo: https://hng-be-s0-production.up.railway.app/me
π» Source Code: https://github.com/Imuaz/HNG-BE-S0
π§© The Challenge
The goal was to create an endpoint that:
- Returns my profile (email, name, tech stack)
- Fetches a random cat fact from an external API
- Generates a dynamic UTC timestamp
- Handles failures gracefully
- Follows a specific JSON format
Example response:
{
"status": "success",
"user": {
"email": "your.email@example.com",
"name": "Your Full Name",
"stack": "Node.js/Express"
},
"timestamp": "2025-10-17T14:23:45.678Z",
"fact": "Cats sleep 70% of their lives."
}
Sounds simple, right? But there's more beneath the surface!
βοΈ Tech Stack
- Node.js + Express.js
- Axios β for API calls
- dotenv β for environment variables
- CORS middleware
- Railway β for deployment
- Git & GitHub β for version control
π§ Implementation Highlights
Project Structure
src/
βββ routes/profile.js
βββ services/catFactService.js
server.js
-
server.js
β Initializes Express, handles middleware & routes -
catFactService.js
β Fetches random cat facts with timeout protection -
profile.js
β Returns user info, timestamp, and a cat fact
Key Features
- β Modular architecture
- β Comprehensive error handling
- β Timeout to prevent hanging requests
- β Dynamic timestamps (always up to date)
π Deployment
- Create a
.env
file with the following variables:
USER_EMAIL=your.email@example.com
USER_NAME=Your Name
USER_STACK=Node.js/Express
- Push your code to GitHub
- Deploy on Railway
- Add environment variables in the Railway dashboard
5. Visit the /me
endpoint to test the live API
π§© Challenges & Lessons
External API failures
β Solved using Axios timeout + fallback handlingDynamic timestamps
β Generated fresh ISO 8601 timestamps per requestEnvironment setup
β Used.env
for sensitive config, excluded via.gitignore
Deployment
β Switched to Railway after Render/Vercel restrictions
π§ Key Takeaways
- Always handle API failures gracefully
- Keep your code modular and testable
-
.env
files are your friend for managing config - Learn to deploy β DevOps is part of the job!
- Testing endpoints early saves hours later
π― Conclusion
This project taught me how to design, test, and deploy a real-world API.
If youβre starting with backend development or participating in the HNG Internship, building a project like this is an amazing learning experience.
π Check It Out
- π Live Demo: https://hng-be-s0-production.up.railway.app/me
- π» GitHub Repo: https://github.com/Imuaz/HNG-BE-S0
Top comments (0)