Writing

Blog

Technical notes, implementation guides, and durable lessons from NestJS backend projects.

43 of 43 posts

GraphQL Federation in NestJS: Subgraphs, Entities, and a Gateway
8 min read

GraphQL Federation in NestJS: Subgraphs, Entities, and a Gateway

One GraphQL schema, many NestJS services. We take a code-first GraphQL API and split it into Apollo Federation v2 subgraphs — a users service that owns the User entity, an orders service that extends it — composed by a gateway that plans queries across both without the client ever knowing.

Validation in NestJS: Pipes, DTOs, and Errors That Fit Your API
13 min read

Validation in NestJS: Pipes, DTOs, and Errors That Fit Your API

Pipes are the front door of a NestJS request — they transform and validate input before it ever reaches a service. This post covers the ValidationPipe and DTOs, the options that actually matter (whitelist, transform), parsing and custom pipes, a Zod alternative, generating Swagger/OpenAPI docs from the same DTOs, and how to make validation failures come back in the same error shape as the rest of your API.

Mapped Error Handling in NestJS: Base Exception, Domains, and One Filter
9 min read

Mapped Error Handling in NestJS: Base Exception, Domains, and One Filter

Most NestJS apps throw a mix of HttpException, raw Error, and string messages — so the client gets a different shape every time. This post builds a layered error model instead: a base domain error with stable, namespaced string codes, per-domain exception families with typed constructors, cause-chaining, and a single global filter that renders any of them into one consistent, leak-free response (with an RFC 9457 variant).

Version-Safe Test Data Factories for TypeORM
14 min read

Version-Safe Test Data Factories for TypeORM

Unit tests mock the repository. Integration and e2e tests hit a real database — and that is where you need realistic seed data. The TypeORM ecosystem has no great answer for this, and the libraries that exist break every time TypeORM changes its internals. This post builds a tiny factory library that inverts the dependency: TypeORM becomes a six-line adapter, so upgrading it can never break your seeds.

NestJS Lifecycle Events: From Bootstrap to Graceful Shutdown
5 min read

NestJS Lifecycle Events: From Bootstrap to Graceful Shutdown

The constructor is not where initialization belongs. NestJS gives you five lifecycle hooks — OnModuleInit, OnApplicationBootstrap, OnModuleDestroy, BeforeApplicationShutdown, and OnApplicationShutdown — each firing at a precise moment in the application's life. This post shows you what each one is for, the order they run in, and what graceful shutdown actually looks like in production.

NestJS Injection Scopes: DEFAULT, REQUEST, and TRANSIENT in Production
7 min read

NestJS Injection Scopes: DEFAULT, REQUEST, and TRANSIENT in Production

Most NestJS services are singletons — and that is fine until you need per-request isolation for tenant context, correlation IDs, or stateful helpers. This post explains all three scopes, scope bubbling, durable providers, and when each one belongs in your application.

NestJS Custom Providers: useValue, useClass, useFactory, and useExisting in the Real World
8 min read

NestJS Custom Providers: useValue, useClass, useFactory, and useExisting in the Real World

The official docs show you the four provider shapes. This post shows you when to reach for each one in production code — typed injection tokens, async factory initialization, environment-aware class swapping, alias providers, and a multi-provider plugin system you can extend without touching existing code.

Building and Publishing a NestJS Library: Dynamic Modules, forRoot, and npm
10 min read

Building and Publishing a NestJS Library: Dynamic Modules, forRoot, and npm

Most devs spend their careers installing NestJS libraries. Today you learn how they are built. We reverse-engineer the patterns from @nestjs/typeorm and @nestjs/config — forRoot, forRootAsync, forFeature, custom decorators — then apply them to a real context-aware logger you can publish to npm.

Mocking External APIs in NestJS (Part 2): Stateful Scenarios and Fault Injection with WireMock
8 min read

Mocking External APIs in NestJS (Part 2): Stateful Scenarios and Fault Injection with WireMock

Part 2 of mocking external APIs: the same NestJS backend, now pointed at WireMock in Docker. File-based stubs, a stateful scenario that starts returning 429 after three calls, runtime switching through the __admin API, and network-level faults like connection resets and malformed responses.

Design Patterns in NestJS: Strategy, Observer, and Factory
6 min read

Design Patterns in NestJS: Strategy, Observer, and Factory

Three patterns that come up constantly in NestJS applications — all in the same order-processing domain so you see how they compose. Strategy picks the shipping algorithm at runtime, Factory decouples order creation from usage, and Observer decouples "order placed" from "what to do about it".

Mocking External APIs in NestJS (Part 1): Errors, Rate Limits, and Latency with Mockoon
9 min read

Mocking External APIs in NestJS (Part 1): Errors, Rate Limits, and Latency with Mockoon

Your backend depends on a third-party API you cannot control. We build a requester pattern where the provider base URL is a single env var, then point the whole app at a Mockoon mock that simulates happy paths, 500s, 403s, 429 rate limiting, and slow responses — with the GUI and @mockoon/cli.

NestJS Classes Deep Dive: Abstract Classes, Extends, Implements, and Overrides
7 min read

NestJS Classes Deep Dive: Abstract Classes, Extends, Implements, and Overrides

Most NestJS projects default to interfaces. But abstract classes let you define a contract AND ship shared behavior in one construct. This post covers the template method pattern, hook methods, the override keyword, DTO inheritance, and generic base services — all in a real NestJS notification system.

NestJS Authorization with CASL (Part 2): Conditions and Record-Level Permissions
9 min read

NestJS Authorization with CASL (Part 2): Conditions and Record-Level Permissions

The sequel to the CASL authorization post. We go from "editors can update articles" to "editors can update their own articles" using CASL conditions, subject detection, a two-layer guard plus service check, query filtering, and field-level permissions in NestJS.

NestJS Authorization with CASL: Roles, Abilities, and a Guard That Scales
10 min read

NestJS Authorization with CASL: Roles, Abilities, and a Guard That Scales

A practical way to organize authorization in NestJS using @casl/ability: typed actions and subjects, one permission file per subject, an ability factory, and a guard with a CheckAbility decorator that keeps controllers clean.

NestJS Architecture: DTOs, Services, Transactions, and Boundaries
7 min read

NestJS Architecture: DTOs, Services, Transactions, and Boundaries

A practical discussion about where DTOs should live, how services should receive input, when to create interfaces, and how to organize errors, interceptors, filters, and transactions in a NestJS application.

Real-time chat with NestJS and Socket.io
4 min read

Real-time chat with NestJS and Socket.io

Real-time communication is an intriguing topic, and I wanted to share my thoughts on it. I came across one of my old blog posts about micro frontends, where I developed an interface for a micro frontend chat feature that

How to Integrate Multiple Payment Gateways in NestJS (With Stripe Example)
7 min read

How to Integrate Multiple Payment Gateways in NestJS (With Stripe Example)

NestJS-based payment gateway integration service. It provides a unified interface for processing payments through various payment processors such as Stripe, PayPal, and others. The service handles payment initialization, processing, and refunding, ensuring a seamless payment experience for users.

NestJS TypeORM and Multi-Tenancy
6 min read

NestJS TypeORM and Multi-Tenancy

A practical implementation of multi-tenancy using NestJS and TypeORM, managing multiple databases for customers, with features like database migrations and connection handling. Future improvements could include real-time database verification and a caching layer for better scalability.

Questions generator with NestJS and OpenAI
5 min read

Questions generator with NestJS and OpenAI

Hello fellow coders! This time we are going to have a different post, I am not going to focus on Nestjs technical details instead, I'm going to explain a bit more different concepts than those that we've already seen on

Applying integration test on NestJS with Jest and GitHub Actions
6 min read

Applying integration test on NestJS with Jest and GitHub Actions

Hello fellow coders! Today we are going to talk a bit about tests inside NestJS, let’s start looking at and applying one type of test and later we are going to see another, so the first one will be e2e.

Applying unit tests on NestJS with Jest and GitHub Actions
5 min read

Applying unit tests on NestJS with Jest and GitHub Actions

Hello fellow coders! In this post we are still going to talk about tests, but, instead of e2e we are going to implement unit tests, I’d say they are kind of siblings, however, each one does different things, and they hav

Migrating NestJS project with TypeORM to Prisma
3 min read

Migrating NestJS project with TypeORM to Prisma

Hello fellow coders! Today we are going to replace TypeORM with Prisma inside a simple previous project that we built, it’s gonna be simple and quick, so let’s get started!

Authentication part 3 using NestJS and Postgres database neon.tech
6 min read

Authentication part 3 using NestJS and Postgres database neon.tech

Hello fellow coders! Let's continue our series of NestJS auth flow implementations, and today we are going to add a database integration to keep users saved basically to work with the auth module.

Authentication part 2 using NestJS
3 min read

Authentication part 2 using NestJS

Hey there, fellow coders! Let's continue our NestJS auth flow, right? Today we are going to create the two main modules auth and user, they will be very simple just to go straight to the point.

Implementing an Auth Flow Fast with NestJS
1 min read

Implementing an Auth Flow Fast with NestJS

The first step in a NestJS auth-flow series: project setup, CLI usage, SWC compilation, TypeScript target tuning, and Vercel deployment basics.

Implementing auth flow as fast as possible using NestJS
3 min read

Implementing auth flow as fast as possible using NestJS

Hey there, fellow coders! 🚀 Ready to dive into the world of authentication flows? Buckle up because we're about to take a turbo-charged ride with NestJS to implement auth flow faster than you can say "password reset." I

Building a system as lego with react and micro frontends
7 min read

Building a system as lego with react and micro frontends

Hey! Let's talk, this time, about frontend and one cool approach that I have seen more and more often lately. It is called micro frontends.

Flash-cards apps with OpenIA
6 min read

Flash-cards apps with OpenIA

Hi guys! Let’s start another technical post and this time I did something that I really enjoyed, it was an App that uses the famous OpeanIA, and the best part about everything, this app is a Flashcard app, so you can use

Currency conversion async
6 min read

Currency conversion async

Hi dear reader! This is one more project I did to practice a few technologies, so you'll see NestJS, NextJS, SQS, Tests, and MongoDB, all exciting technologies! I'm sure you'll enjoy this post and project as much as I di