DEV Community

khaybee24
khaybee24

Posted on

Building a Production‑Ready /me API for HNG Stage 0

What This API Does

GET /me returns:

your email, full name, tech stack

a live cat fact from catfact.ninja

a UTC timestamp

Prewarms the cat fact API to speed up first request

Timeout protection (no hanging requests)

Rate limiting (prevents abuse — only X requests/min)

HTTPS keep‑alive for faster network performance

Helmet + CORS automatically enabled

Fully JSON standardized responses

🛠 Tech Stack Used

Node.js + Express

Axios (with timeout + keep‑alive)

Helmet, CORS, Rate Limiter

Environment variables via dotenv

*Key Optimizations You Won’t See in Most Stage 0 Submissions
*

Timeout Guard — avoids waiting forever for API response

HTTPS Keep‑Alive — reuses TCP connections for faster calls

Silent Prewarm — API fetch begins before the first user request

Smart Retry (only on startup — no noisy failures)

Rate Limiting — protects against denial‑of‑service

Sample code

const express = require('express');
const axios = require('axios');


app.get('/me', async (req, res) => {
const timestamp = new Date().toISOString();
const fact = await fetchCatFact();


return res.status(200).json({
status: 'success',
user: {
email: process.env.USER_EMAIL,
name: process.env.USER_FULLNAME,
stack: process.env.USER_STACK
},
timestamp,
fact: fact || 'Could not fetch a cat fact right now — try again in a moment.'
});
});
Enter fullscreen mode Exit fullscreen mode

*Final Thoughts
*

This is the kind of attention to detail that makes you stand out. Even at Stage 0, shipping something that looks like real production work sends a strong message.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.