This is an opinionated template for Nestjs projects.
I found that there are many Nestjs projects in my career, and they are all similar in structure. So I created this template to make it easier to start a new Nestjs project.
- Platform: Fastify
- CORS @fastify/cors
- Compression: @fastify/compress
- Database:
- ORM: Prisma
- Cache: Redis @songkeys/nestjs-redis
- Logger: Pino
- nestjs-pino
- pino-pretty in development
- pino-sentry-transport
- Swagger: @nestjs/swagger
- with nest-cli plugin enabled
- Throttler: @nestjs/throttler
- with Redis cache: nestjs-throttler-storage-redis
- Testing: removed! (Sorry, I don't write tests. 😅)
Init environment variables:
cp .env.example .env
Install dependencies:
npm install
Start DB docker:
npm run docker:db
Generate Prisma client:
npm run prisma:generate
Migrate database:
npm run prisma:migrate:dev
Run the app:
npm run start:dev
Docker:
# building new NestJS docker image
docker-compose build
# or
npm run docker:build
# start docker-compose
docker-compose up -d
# or
npm run docker
In Node.js Environment:
npm install
npm run build
./start_prod.sh
Development:
npm run prisma:migrate:dev
Production:
npm run prisma:migrate:deploy