The journey continues! After setting up my project structure on Day 1, today was all about building the heart of my microservices platform: the backend API.
If you missed Day 1, you can catch up here: [https://dev.to/michellewanjiru/day-1-of-my-30-day-cloud-devops-challenge-project-setup-2a5a?trk=public_post_comment-text]
What I Set Out to Do Today
Build a working REST API that can:
- Respond to HTTP requests
- Return JSON data
- Serve as the foundation for my microservices platform
Simple, right? Well... let me share how it actually went.
The Tech Stack I Chose
I decided to go with Node.js + Express for my backend because:
- JavaScript is everywhere (frontend, backend, even DevOps tools)
- Express is lightweight and beginner-friendly
- I already had Node.js installed on my Ubuntu system
Step-by-Step: What I Actually Did
1. Initial Setup
cd backend
npm init -y # Creates package.json
npm install express # Web framework
npm install --save-dev nodemon # Auto-restarts server on changes
What I learned: package.json is like a shopping list for your project. Every tool you add gets listed there, making it easy to share your project with others.
2. Writing My First Server
I created server.js with three endpoints:
const express = require('express');
const app = express();
const PORT = 8000;
// Root endpoint
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the Microservices Platform API', status: 'running' });
});
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'healthy', service: 'backend-api', timestamp: new Date().toISOString() });
});
// Users endpoint (mock data for now)
app.get('/users', (req, res) => {
res.json([
{ id: 1, name: 'Alice', email: 'alice@example.com' },
{ id: 2, name: 'Bob', email: 'bob@example.com' },
{ id: 3, name: 'Charlie', email: 'charlie@example.com' }
]);
});
app.listen(PORT, () => {
console.log(` Server running on http://localhost:${PORT}`);
});
Understanding each part:
-
app.get()defines what happens when someone visits a URL -
(req, res) => {}is a function that handles the request and sends a response -
res.json()sends data back as JSON (the language of APIs)
3. The Challenge That Almost Stopped Me
I tried running my server with:
npm run dev
And got this error:
npm error Missing script: "dev"
My reaction: 😅 Wait, what? I thought I had this!
How I diagnosed it:
npm run # Shows all available scripts
Only test was showing. I had completely forgotten to add the "dev" script to my package.json!
The fix: I opened package.json and added:
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
}
Lesson learned: Never assume your configuration is correct. Always verify with simple commands.
4. The Moment It Finally Worked
After fixing the script, I ran:
npm run dev
And saw:
Server running on http://localhost:8000
Then in another terminal:
curl http://localhost:8000/
Response:
{"message":"Welcome to the Microservices Platform API","status":"running"}
I literally cheered in my chair.🎉 My first API was alive!
Testing All Endpoints
Here's what each endpoint returned:
| Endpoint | Response |
|---|---|
GET / |
Welcome message |
GET /health |
Service status with timestamp |
GET /users |
List of 3 mock users |
All working perfectly!
Key Learnings from Day 2
Technical Concepts I Gained:
-
HTTP Methods:
GETis how you retrieve data from a server - JSON: The universal language of APIs — both request and response
- Ports: Think of them like doors — 8000 is the door my API listens on
-
Endpoints: Specific URLs that do specific things (
/health,/users) - Package.json scripts: Custom commands to automate repetitive tasks
Problem-Solving Skills:
-
Diagnosing errors:
npm runhelped me see what was actually available - Reading error messages: "Missing script" told me exactly what was wrong
- Step-by-step verification: Test each piece before assuming everything works
Mindset Shifts:
- Done is better than perfect: My first API doesn't have a database yet, and that's okay
- Celebrate small wins: Getting that first curl response was genuinely exciting
- Embrace mistakes: The missing script error taught me more than if everything worked perfectly
Tips for Anyone Starting Their Own API
- Start simple. My API only does 3 things right now — that's enough!
- Test as you go. Don't write 100 lines of code before testing. Test after each endpoint.
- Use curl or browser. It's satisfying to see your API respond in real-time.
- Save your package.json changes. I almost forgot this one!
- Keep notes. Document what you learn, especially the mistakes.
A Quick Thank You
To everyone following along and the community helping me debug, your support means everything. Special shoutout to those who reminded me to check my package.json scripts!
What's Next (Day 3)
Tomorrow, I'm building a frontend that will:
- Fetch data from my API
- Display the list of users
- Show the health status
It's going to be the first time my frontend and backend talk to each other!
Links & Resources
- GitHub Repository: Production-Ready-Microservices-Platform
- Express Documentation: expressjs.com
- Nodemon: nodemon.io
Let's Connect!
Are you also learning backend development? Building your first API? I'd love to hear about your journey!
Drop a comment below or connect with me on LinkedIn at https://www.linkedin.com/in/michelle-wanjiru-420877275/?lipi=urn%3Ali%3Apage%3Ad_flagship3_detail_base%3BHw%2F74ryNQ7CjXqDkL3k7eQ%3D%3D. Let's learn together!
This is Day 2 of my 30-Day Cloud & DevOps Challenge. Follow along as I build a complete microservices platform from scratch!
Top comments (0)