Chapter 1 - Initialize the project with NestJS¶
In this chapter, you will create a new NestJS project with the NestJS CLI.
You will then be able to start the application to see if it runs correctly.
Steps¶
Warning
Make sure to have your environment set up! You can check the Install and configure Visual Studio Code, Install and configure Docker and Install and configure Dev Containers tutorials if needed.
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.
- The
node_modules
directory contains all the dependencies needed to run your project. - The
src
directory contains all the source code of your project. - The
package-lock.json
file is the main file of your project. It defines the available scripts, the dependencies and some information regarding your project.
Start the NestJS application¶
In a terminal, execute the following command(s). | |
---|---|
The output of the command should look similar to this.
Check the results¶
You can now access your NestJS application on http://localhost:3000. 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:3000.
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.