Chapters of From Frontend to Full-Stack Backend

Week 4 - Capstone + NestJS + System Design + DrillChapter 25 of 282 min read

NestJS crash course - a new framework through Express experience

Module, controller, provider, guard, interceptor - similarities and differences with Express

Many job descriptions ask for NestJS - you may have seen it in a post a few days ago too. There is nothing to fear: NestJS actually stands on top of Express, it just has its own discipline. The ideas you arranged by hand all this time - separate folders, middleware, validation - NestJS puts them into a mandatory shape. So for you this is not a new language, it is familiar ideas with new names.

Five core ideas

  • Module - everything of one feature tied in one box: its controller, service, dependencies. The formal shape of your routes+service split.
  • Controller - only taking requests and giving responses, routes declared with decorators.
  • Provider (service) - the place of the real work, marked with @Injectable(); Nest itself supplies it wherever needed (dependency injection).
  • Guard - the Nest version of your requireAuth middleware: it decides whether to let someone in.
  • Interceptor - working wrapped around the request's coming and going - like unifying the response format, measuring time, logging.
@Controller("users")
export class UsersController {
  constructor(private usersService: UsersService) {}

  @Get()
  @UseGuards(AuthGuard) // in place of your requireAuth
  findAll() {
    return this.usersService.findAll();
  }
}

The biggest difference is dependency injection: in Express you imported and joined things yourself, in Nest the framework itself builds each part and delivers it where needed. It feels unfamiliar at first, but it makes testing much easier - you can put a fake in place of the real service. And since the discipline is the same for everyone, code feels familiar even in a new team.

Keep the task limited: do not rewrite the whole capstone in Nest. Build a small part with Nest - like just auth and one CRUD - and see. The goal is not mastering the framework, it is being able to explain the ideas with confidence when asked 'Do you know NestJS?' in an interview.

The mistake everyone makes

Fearing NestJS as something completely new, or the opposite - sitting down to rewrite the whole project in Nest. The right measure: reading it matched against Express ideas, and building a small part by hand.

Today's practice

Open a small NestJS project and build just one resource (like products) - with module, controller, service, and one guard. While building, write each part's Express equivalent beside it.

How to say it in an interview

NestJS is a disciplined framework standing on Express - features divided by module, controllers only for request-response, real work in providers, auth checks with guards. The structure I arranged by hand in Express, Nest gives as a shape, and with dependency injection testing becomes easy.

All chapters of From Frontend to Full-Stack Backend