Under Construction

Blog Coming Soon

The site is currently under construction, but I'm excited to launch it soon!

Building Type-Safe APIs with TypeScript and Express

TypeScript has changed the way we build backend applications by bringing type safety to JavaScript. In this post, I'll demonstrate how to create a robust API using TypeScript, Express, and Zod for validation.

// Lorem Ipsum
import express from 'express';
import { z } from 'zod';

const validateUserInput = (req, res, next) => {
  const schema = z.object({
    username: z.string().min(3).max(20),
    email: z.string().email(),
    age: z.number().min(18).optional()
  });
  
  try {
    req.validatedData = schema.parse(req.body);
    next();
  } catch (error) {
    res.status(400).json({ error: error.errors });
  }
};
Full post coming soon →