This is an example of how to use nestjs with jwt and typeorm to build a basic blog API.
- Start the mysql container using docker
$ docker-compose up -d
- Start the nestjs process using to following
$ yarn start
If you're going to use this example in production (or your own verison of it) it's recommended to run using the 'complied' JS version from dist. You can do this by using the following command
$ yarn start:prod
This command will also clean and build your dist folder
For development, the best command to use is
$ yarn start:dev
This will start nodemon to reload our script when there's been any changes in the src directory
Unit tests can be ran by simply using the test
script
$ yarn test
This will run jest on all .spec.ts
files.
End to end tests can be run by using the following command
$ yarn test:e2e
this will run jest on all .e2e-spec.ts
files.
Use jest to show you a coverage of your tests
$ yarn test:cov
Want to get started on your own NestJS application? Simply install the nest-cli npm i -g @nestjs/cli
and use the command nest new my-application
to create a new directory called my-application
with nestjs ready to go!
I used a variety of packages to develop this example api. Here's a list of them and where I got them from
- Nestjs
- @nestjs/typeorm A typeorm module for nestjs
- @nestjs/passport An easy to use module for passport include AuthGuards
- @nestjs/jwt A JWT module for nestjs
- nestjs-community
- nestjs-config A config module for nestjs (envs)
- typeorm typeorm is an orm for TypeScript