This repository provides simple boilerplate for implementing authentication in a NestJS application using JSON Web Tokens (JWT).
- JWT Authentication: Secure authentication using JSON Web Tokens.
- Role-Based Access Control: Easily extendable to support different user roles and permissions.
- Environment Configuration: Centralized configuration management using @nestjs/config.
- TypeORM Integration: Database management with TypeORM, supporting PostgreSQL out of the box.
- Redis Integration: Redis support via ioredis for session management, caching, or other use cases.
- Scalability: Modular architecture, making it easy to extend and scale.
- Best Practices: Includes TypeScript, ESLint, and Prettier for code quality and consistency.
Ensure you have Docker and Docker Compose installed on your machine.
-
Create your environment variables file by copying
.env.example
to.env
:cp .env.example .env
-
Update the
.env
file with your specific environment configurations.
The recommended way to run the project is by using Docker. Docker Compose will handle all the necessary services.
To spin up the entire application (including the database, Redis, and other services), run:
$ docker-compose up --build
This command will build the Docker images if they don't exist, and start the containers as defined in your docker-compose.yml file.
To stop the running containers, press CTRL+C or run:
$ docker-compose down
This command will stop and remove the containers, but the data in the volumes (e.g., PostgreSQL and Redis data) will be preserved.
Testing can be done inside the Docker container or on your local machine if you have Node.js installed.
To run the tests inside the Docker container:
$ docker-compose exec app npm run test
If you prefer running tests on your local machine:
- Install the dependencies:
$ npm install
- Run the tests:
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov