Chapter 4 - Initialize the backend project with NestJS¶
With the later chapters, you have created a simple drawing application that allows you to draw in your browser.
Now, what if it was possible to draw with multiple people at the same time using your drawing application? That would be kind of cool right?
In this chapter, you will create a new NestJS backend project with the NestJS CLI.
You will then be able to start the application to see if it runs correctly.
The backend will allow all players to connect and exchange the points they are drawing.
Info
All the following steps will be executed at the root level of your working directory.
Steps¶
Install NestJS CLI¶
The NestJS CLI allows to create and manage NestJS projects.
In a terminal, execute the following command(s). | |
---|---|
Create a NestJS project¶
Create a NestJS project in the local directory.
In a terminal, execute the following command(s). | |
---|---|
NestJS should create a project that looks like this in your working directory.
Change the port configuration¶
Change the port from 3000
to 4000
.
backend/src/main.ts | |
---|---|
Start the NestJS application¶
The output of the command should look similar to this.
Check the results¶
You can now access your NestJS application on http://localhost:4000. You should see the message Hello World!
.
To stop your NestJS application, press Ctrl+C in your terminal.
Summary¶
Congrats! You have a default NestJS application running! You are now able to create NestJS projects and start/stop NestJS applications.
Go further¶
Are you able to change the message to Hello BeeScreens!
? Expand the next component to see the answer!
Show me the answer!
The entrypoint of the NestJS application is the main.ts
file.
It loads the AppModule
module.
The AppModule
is a collection of other dependencies that can be loaded as a single unit.
The AppModule
loads the AppController
controller and the AppService
service.
The AppController
is the the entry point of your request when you access http://localhost:4000.
The method getHello()
call the method this.appService.getHello()
from the AppService
.
You can change the following code to display Hello BeeScreens!
.
Save your changes. NestJS should automatically restart the application. Access http://localhost:3000. You should see the expected result.