DEV Community

Fiona Nyadero
Fiona Nyadero

Posted on

💻Building and Deploying My First Express API - HNG Stage 0 Task

🚀 #HNG13 Stage 0 Task Completed!

This week, I built and deployed a simple yet dynamic Express.js API as part of the HNG Internship.
The challenge was to create an endpoint that returns:

My personal details (from a predefined object),

A timestamp, and

A random cat fact fetched from a public API 🐱.

Even though it sounds simple, the process was a great refresher on how real-world APIs are structured, tested, and deployed.

🧠 What I Did

1️⃣ Setting Up the Project
I initialized a new Node.js project and installed the required dependencies:

npm init -y
npm install express axios dotenv
Enter fullscreen mode Exit fullscreen mode

2️⃣ Writing the Server Code
I used Express to handle HTTP requests and Axios to fetch data from an external API.
Here’s what my route does:

Sends my user details and the current timestamp.

Fetches a cat fact from an API.

If the API fails, it returns a fallback message:
"Cats are mysterious, even when APIs fail."

This taught me how to handle API errors gracefully — something developers face often.

3️⃣ Environment Setup
I created a .env file to store environment variables securely, like:

PORT=3000
Enter fullscreen mode Exit fullscreen mode

and added .gitignore to ensure sensitive files aren’t pushed to GitHub:

node_modules
.env
Enter fullscreen mode Exit fullscreen mode

4️⃣ Deployment on Railway
This was my favorite part!
I pushed my project to GitHub and deployed it seamlessly on Railway:

Connected my GitHub repo

Set the environment variable PORT = 3000

Clicked Deploy!

Within seconds, my Express API was live at:
🌐 https://hng13-stage0-backend-production.up.railway.app
😺 https://hng13-stage0-backend-production.up.railway.app/me

🧩 What I Learned

This task taught me:

The importance of clean and readable API responses.

How to use environment variables for secure configuration.

How to deploy Express applications to production using Railway.

How to log and handle errors gracefully without breaking the API.

I also had to pay close attention to my file structure/naming and what is in my package.json

It’s amazing how such a small task can sharpen so many essential backend skills!

Top comments (0)