NestJS Boilerplate
Boilerplate repo for a NestJS service.
Features
This boilerplate was generated with the NestJS CLI and is setup with these additional features for production-grade services:
- Commands to package as a docker image along with image scanning using Snyk
- Simple Github Actions CI to build, lint, and test on every PR
- Folder layout to keep framework-level modules separate from feature modules
- Structured, high-performance, JSON logging via Pino Logger
- NestJS Swagger integration out of the box
- Health Checks via Terminus
- Unit, integration, and e2e tests through Jest and supertest
Todo
- Config abstraction using decorators
Prerequisites
Please make sure you have the following before starting with this boilerplate:
Setup
Install dependencies using NPM.
$ npm install
For managed service dependencies, add them to docker-compose.yml
and then run the following to spin them up:
$ docker compose up -d
Developer Workflow
These are some useful commands as part of your dev workflow:
# Run the app
$ npm start # Same as below
$ npm run start:dev # Run app and restart on save
$ npm run start:prod # Run in production mode
# Tests
$ npm run test # Run tests (unit & integration) once
$ npm run test:watch # Auto-rerun tests on save
$ npm run test:cov # Run with code coverage
$ npm run test:e2e # Run e2e tests once
$ npm run test:e2e:cov # Run e2e tests with coverage
# Style/formatting
$ npm run lint # Run eslint & fix lint errors
$ npm run format # Run prettier & fix style errors
# Convenience
$ npm run precommit # Convenience helper that runs build,
# format, lint, and test. NOT an actual
# precommit hook, but it's useful to run
# before committing
# Docker
$ npm run docker # Build and then run the app in docker
$ npm run docker:check # Runs a build and a scan
$ npm run docker:build # Builds the service into a docker image
$ npm run docker:run # Run the service as a docker container
$ npm run docker:scan # Runs a docker scan using Snyk
# NOTE: These are rate limited unless you
# get an account with them
Misc
- To check swagger while in dev mode, navigate to http://localhost:3000/swagger