DEV Community

Frank Micheal
Frank Micheal

Posted on

HNG 13 Backend Stage 0 – Building a Simple API with Node.js and Express

πŸš€ 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

  1. Project setup
   npm init -y
   npm install express axios cors
Enter fullscreen mode Exit fullscreen mode
  1. Created folder structure
   src/
   β”œβ”€β”€ app.js              # Express setup
   β”œβ”€β”€ routes/
   β”‚   └── profile.js      # /me route logic
   └── services/
       └── cat-facts.js    # External API integration
Enter fullscreen mode Exit fullscreen mode
  1. Integrated the Cat Facts API
    I used Axios to fetch a random fact from the endpoint https://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."

  2. 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."
   }
Enter fullscreen mode Exit fullscreen mode
  1. 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)