When I saw the HNG Backend Stage 0 challenge build a /me endpoint that returns my profile plus a live cat fact,I thought: “Simple, right?”
Turns out, even “simple” APIs teach you big lessons about error handling, module systems, and the chaos of third-party dependencies. Here’s how I built it, what went wrong, and how I fixed it all in TypeScript + Express, deployed from my local machine.
🎯 Why This Task Matters
This isn’t just a JSON blob. It’s a microcosm of real backend work:
✅ Dynamic data: Fresh timestamp on every request
🌐 External API integration: Real-time cat facts from catfact.ninja
🛡️ Fault tolerance: Graceful fallbacks when APIs fail
🚪 Instant public access: No cloud deployment needed thanks to ngrok!
The Core Logic: /me Handler
The magic happens in under 30 lines. Key features:
- Live timestamp (ISO 8601 UTC)
- Fresh cat fact per request (with 5s timeout)
- Fallback fact if the cat API flakes out
🚧 The Module System Trap (ESM vs CommonJS)
My biggest headache? This runtime crash:
Cause: I used ESM-style named imports with a CommonJS package (express):
Fix: Use type-only aliases (zero runtime cost):
Lesson: TypeScript compiles ≠ Node.js runs. Always test with tsx or compiled JS!
🌐 Deployment? Meet ngrok.
Since cloud platforms like Vercel were off-limits, I went local first:
- Ran my Express server: npm run dev → http://localhost:3000
- Fired up ngrok:
ngrok http 3000
- Got an instant public URL: https://f8ffe71c697b.ngrok-free.app
✅ No Docker
✅ No CI/CD
✅ No waiting for builds
Just pure, tunnelled, localhost magic.
🔑 Key Takeaways
- Local can be public ngrok turns localhost into a shareable URL in seconds—perfect for demos, testing, and challenges like this.
- Third-party APIs will fail Always code for failure. A fallback fact kept my endpoint alive during catfact.ninja outages.
- ESM + CommonJS = handle with care Use type aliases for Express types in ESM projects. Avoid runtime destructuring.
- Small tasks, big insights This “simple” endpoint taught me about timeouts, env vars, module systems, and resilient design.
📦 Try It Yourself!
- Github Repo: https://github.com/towbee98/fictional-octo-chainsaw
- Run locally:
Then hit your ngrok URL + /me and watch the cat facts roll in! 🐾
👋 Final Thought
You don’t need a server farm to build something useful. With TypeScript, Express, and ngrok, your laptop becomes a global API endpoint.
And if nothing else,now you know that cats spend 70% of their lives sleeping. Go take a nap. You’ve earned it.
Built for Backend Wizards . Stage 0: complete.
Top comments (0)