/nestjs-starter-project

Starter project with Typeorm and centralized environment configuration. It's also comes with Dockerfile and docker-compoe file. This features Typeorm auto migration

Primary LanguageTypeScript

Nest Logo

Description

Starter project with Typeorm and centralized environment configuration. It's also comes with Dockerfile and docker-compoe file. This features Typeorm auto migration at runtime in docker container before the nest js start. Forked from Nest framework TypeScript starter repository

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Create migration file

Create ormconfig.json first in the root folder to set up your database. For reference read the ormconfig.json configuration.

$ npm run migration:generate "AddSomeTable"

This will create a migration file named {timestamp}-AddSomeTable.ts on /migration folder under the database module

Run migration on local machine

# this will run migration file
$ npm run db:migrate

# this will revert migration file
$ npm run db:revert

Docker build

# build docker images
$ docker build . -t nest-starter-project

# or run docker-compose
$ docker-compose up --build

Auto migration

Auto migration using typeorm migrationsRun at startup

Environment Configuration

Environment configuration done by loading all declared environtment in config module. If you want to add more configuration, add it to config.service.ts in config module

Interceptor

This starter project also comes with interceptor. These are:

  • Entity not found interceptor
    This interceptor will return 404 status code if the error type is EntityNotFoundError
  • Plain to class interceptor
    This interceptor will transform returned data match to the DTO, so we dont have to transform it manually
  • Response transform interceptor
    This interceptor will transform the response object so you can make a custom structur of the response object

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

Nest is MIT licensed.