Building a Simple NestJS Controller with @Controller Decorator
📖 Scenario: You are creating a simple web server using NestJS. You want to organize your routes by creating a controller that handles HTTP requests for a specific path.
🎯 Goal: Build a NestJS controller class using the @Controller decorator to define a route prefix.
📋 What You'll Learn
Create a controller class named
AppControllerUse the
@Controller decorator with the path 'app'Add a method named
getHello inside the controllerUse the
@Get decorator on the getHello method with no path argumentReturn the string
'Hello World!' from the getHello method💡 Why This Matters
🌍 Real World
Controllers in NestJS organize routes and handle HTTP requests in web applications and APIs.
💼 Career
Understanding controllers and decorators is essential for backend development with NestJS, a popular Node.js framework.
Progress0 / 4 steps