NestJS Boilerplate
- Node.js v16+
- PostgreSQL
# install packages
$ npm install
# init database
$ docker compose up -d init_db
If you encounter the error related to argon2
then uncomment the following command in docker-compose.yml
file
command: sh -c "npm rebuild argon2 --build-from-source && npm run typeorm:run-migration && npm run seed:run"
# run migrations
$ npm run typeorm:run-migrations
# generate migrations
$ npm run typeorm:generate-migration --name=migration-name
If script above doesn't work, try using git bash
, change $npm_config_name
in package.json to %name%
and run the following script:
$ name=migration-name npm run typeorm:generate-migration
- Create seed file with the following command:
# `Demo` is name of entity.
$ npm run seed:create -- --name=Demo
- Go to
src/database/typeorm/seeds/demo/demo-seed.service.ts
. - In
run
method extend your logic.
$ npm run seed:run
With $npm_config_name
in package.json
# Generate module
$ npm run module:generate --name=module-name
# Generate controller
$ npm run controller:generate --name=controller-name
# Generate service
$ npm run service:generate --name=service-name
With %name%
in package.json
# Generate module
$ name=demo npm run module:generate
# Generate controller
$ name=demo npm run controller:generate
# Generate service
$ name=demo npm run service:generate
Module, controller & service of Demo will be created in src/modules/demo
- Change the desired database name in the
gen-entity-local
script inpackage.json
"gen-entity-local": "npx typeorm-model-generator -h localhost -d <YOUR-DATABASE-NAME> -u postgres -x postgres -e postgres -o src/database/typeorm/generated --skipTables=migrations,spatial_ref_sys --noConfig --cf=none --namingStrategy=./src/config/namingStrategy",
- Run the following command
$ npm run gen-entity-local
The new entities can be found at src/database/typeorm/generated
folder
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# unit tests in watch mode
$ npm run test:watch
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov