First steps
Setting up a new project is quite simple with the Nest CLI. With npm installed, you can create a new Nest project with the following commands in your OS terminal:
npm i -g @nestjs/cli nest new project-nameThe project-name directory will be created, node modules and a few other boilerplate files will be installed, and
a src/ directory will be created and populated with several core files.
Directoryproject-name
Directorynode_modules/
- …
Directorysrc
- app.controller.spec.ts
- app.controller.ts
- app.module.ts
- app.service.ts
- main.ts
Directorytest
- app.e2e-spec.ts
- jest-e2e.json
- .eslintrc.js
- .gitignore
- .prettierrc
- nest-cli.json
- package-lock.json
- package.json
- README.md
- tsconfig.build.json
- tsconfig.json
The main.ts includes an async function, which will bootstrap our application:
import { NestFactory } from '@nestjs/core';import { AppModule } from './app.module';
async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(process.env.PORT ?? 3000);}bootstrap();Running the application
nest start --watchThis command starts the app with the HTTP server listening on the port defined in the src/main.ts file.
Once the application is running, open your browser and navigate to http://localhost:3000/. You should see the
Hello World! message.