DEV Community

tunde
tunde

Posted on

๐Ÿฑ Building a Minimal /me Endpoint with Pure Node.js (No Frameworks) - HNG Internship Stage 0

As part of the HNG Internship Stage 0 backend task, I was asked to build a simple REST API that returns my profile information along with a dynamic cat fact from an external API.

Rather than using Express or any framework, I decided to go bare-metal โ€” using just Node.jsโ€™ built-in http module.

This was a fun challenge that made me revisit the basics of how servers, routes, and responses actually work under the hood.


The goal was to create a GET endpoint at /me that returns a JSON response like this:

{
  "status": "success",
  "user": {
    "email": "your@email.com",
    "name": "Your Full Name",
    "stack": "Node.js/Express"
  },
  "timestamp": "current UTC time in ISO 8601 format",
  "fact": "random cat fact from Cat Facts API"
}
Enter fullscreen mode Exit fullscreen mode

Dynamic data for the "fact" field comes from the Cat Facts API

๐Ÿ› ๏ธ Technologies Used

Just the essentials:

๐ŸŸข Node.js

๐Ÿ’ป Built-in HTTP module

๐ŸŒ Native Fetch API (available in Node 18+)

No Express, no frameworks, no extra dependencies, just JavaScript.

๐Ÿงฉ How It Works

1.The server listens for all incoming HTTP requests.

2.If the route matches /me, it:

  • Fetches a random cat fact from https://catfact.ninja/fact
  • Builds a structured JSON object containing my profile and the fact
  • Sends it back with Content-Type: application/json

3.If anything goes wrong (like network errors), it falls back to a default cat fact.

4.Any other route returns a 404 Not Found.

๐Ÿงช Live Demo

๐ŸŒ Live API:
https://hng13-be-stage-0-production.up.railway.app/me

๐Ÿงพ GitHub Repository:
https://github.com/tundealabi/hng13-be-stage-0

/me endpoint response

Top comments (0)