Introduction
Node.js lets you use JavaScript on the server. Combined with Express and PostgreSQL, it's a stack used widely across African tech companies.
Basic Express server
import express from "express";
const app = express();
app.use(express.json());
app.get("/health", (_req, res) => {
res.json({ status: "ok" });
});
app.listen(3001, () => console.log("API running on :3001"));RESTful routes
app.get("/api/tutorials", async (_req, res) => {
const tutorials = await prisma.tutorial.findMany();
res.json({ tutorials });
});
app.post("/api/tutorials", async (req, res) => {
const tutorial = await prisma.tutorial.create({ data: req.body });
res.status(201).json({ tutorial });
});Validation with Zod
import { z } from "zod";
const tutorialSchema = z.object({
title: z.string().min(3),
slug: z.string().min(3),
category: z.string(),
});
app.post("/api/tutorials", (req, res) => {
const parsed = tutorialSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: parsed.error.issues[0].message });
}
// create tutorial...
});Error handling middleware
app.use((err, _req, res, _next) => {
console.error(err);
res.status(500).json({ error: "Internal server error" });
});Deploying in Africa
Consider Render, Railway, or AWS with regions close to your users (e.g. af-south-1 in Cape Town) for lower latency.
Written by
JO
James Okonkwo
Backend Engineer, Lagos
Published April 20, 2025
James designs APIs for payment and logistics platforms serving millions of users.
