Build a modular REST API with NestJS framework.
- What Is This?
- Getting Started
- Database Migrations
- Tests
- Environment Configuration
- API Documentation
- Authentication
- License
- Maintainers
This is a NestJS RESTful API starter that includes JWT authentication, OpenAPI 3 documentation, and TypeORM integration.
The reason I maintain it is because using this template allows you to quickly set up a production-ready RESTful API with minimal boilerplate code.
Create a dotenv file and fill it out with the appropriate values.
cp .env.example .env
Install dependencies
npm install
Run the application
npm run dev
HMR(Hot Module Reload) is configured with webpack.
If you don't require incremental database migrations, set the DB_SYNC environment variable to true. This will continuously synchronize the database structure with the schema defined in the codebase.
However, DO NOT set DB_SYNC to true in a production environment, as doing so may result in data loss!
Make sure to use npm for the following commands, as yarn does not support $npm_config_name
.
npm run migration:generate --name=AddAgeColumnToUser
Migration files are located in the src/migrations
directory.
npm run migration:run
Using Docker:
docker exec nest npm run migration:run
Revert the last migration
npm run migration:revert
# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:cov
@nestjs/config
has been used, so you can just inject ConfigService
to read environment variables from the dotenv file.
OpenAPI 3.0 has been configured, and the API documentation is hosted at BASE_URL/api/docs
.
JWT authentication has been configured.
MIT