Basic Implementation
Based on NestJS documentation, NestJS aims to be platform-agnostic framework. For current implementation, NestJS supports implementation with ExpressJS as the default config and Fastify.
Install Fastify (Optional)
To use Fastify, you can read this documentation or you can add another package:
bash
npm i --save @nestjs/platform-fastify
bash
yarn add @nestjs/platform-fastify
Implementation on main.ts
ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
ts
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
await app.listen(3000, '0.0.0.0');
}
bootstrap();
How to Generate Module, Controller, and Service
bash
nest g module <module-name>
bash
nest g controller <controller-name>
bash
nest g service <service-name>