0
0
NestJSframework~30 mins

First NestJS application - Mini Project: Build & Apply

Choose your learning style9 modes available
First NestJS application
📖 Scenario: You want to create a simple web server using NestJS that responds with a greeting message when accessed.
🎯 Goal: Build a basic NestJS application with a controller that returns 'Hello, NestJS!' when visiting the root URL.
📋 What You'll Learn
Create a NestJS application main file
Set up a controller named AppController
Add a route handler for GET requests on the root path /
Return the exact string 'Hello, NestJS!' from the route handler
💡 Why This Matters
🌍 Real World
NestJS is used to build scalable and maintainable server-side applications with TypeScript and Node.js. This project shows how to start a simple web server.
💼 Career
Understanding how to create a basic NestJS app is essential for backend developers working with modern Node.js frameworks in professional environments.
Progress0 / 4 steps
1
Create the main application bootstrap file
Create a file named main.ts and write code to bootstrap a NestJS application using NestFactory.create(AppModule). Import AppModule from ./app.module. Use await app.listen(3000) to start the server on port 3000.
NestJS
Need a hint?

Use NestFactory.create(AppModule) to create the app and app.listen(3000) to start the server.

2
Create the application module
Create a file named app.module.ts. Import Module from @nestjs/common. Define a class AppModule decorated with @Module that declares AppController in its controllers array. Import AppController from ./app.controller.
NestJS
Need a hint?

Use @Module decorator with controllers array including AppController.

3
Create the application controller
Create a file named app.controller.ts. Import Controller and Get from @nestjs/common. Define a class AppController decorated with @Controller(). Add a method getHello() decorated with @Get() that returns the string 'Hello, NestJS!'.
NestJS
Need a hint?

Use @Controller() on the class and @Get() on the method returning the greeting string.

4
Run and verify the NestJS application
Ensure all files are saved. Run the NestJS application using npm run start or node dist/main.js after building. Visit http://localhost:3000/ in a browser to see the text 'Hello, NestJS!'. Add the @Controller() decorator to AppController if missing.
NestJS
Need a hint?

Make sure the @Controller() decorator is present on AppController to handle routes.