A NestJS TypeScript Boilerplate project with the following features:
- TypeORM for database interactions.
- JWT Authentication using Passport.js.
- Swagger integration for API documentation.
- Scalable architecture with modular organization.
- Ready-to-use configuration for development and production.
- Authentication: Secure JWT-based authentication with Passport.js.
- TypeORM Integration: Preconfigured ORM with support for migrations and multiple databases.
- Swagger Documentation: Interactive API documentation accessible via
/api
. - Modular Architecture: Easily extendable project structure.
- Environment Configuration: Centralized configuration management with
.env
files. - Preconfigured Scripts: For development, production, and testing.
- Node.js (>= 16.x)
- npm (>= 8.x)
- A database (MySQL, PostgreSQL, etc., compatible with TypeORM)
-
Clone the repository:
~$ git clone https://github.com/ashenud/nest-rest-api.git ~$ cd nest-rest-api
-
Install dependencies:
~$ npm install
-
Configure environment variables: Copy the
.env.example
file to.env
and update the values:cp .env.example .env
This boilerplate uses JWT-based authentication. To access protected routes:
- Register or log in to get a JWT token.
- Use the token in the
Authorization
header asBearer <token>
.
-
Run the development server:
~$ npm run start:dev
-
Swagger documentation: Visit http://localhost:3000/api to view the Swagger UI.
A docker-compose.yml
is included for containerized deployments.
-
Configure environment variables if not done previously: The MySQL container will be built using the values from the .env file. Make sure to set up the .env file before starting the containers.
cp .env.example .env
-
Build and Run the container:
docker-compose up -d
-
Install dependencies:
docker exec -it nest-rest-api npm install
-
Run the development server:
docker exec -it nest-rest-api npm run start:dev
src/
├── common/ # Common utilities and decorators
├── modules/ # Feature modules
│ ├── auth/ # Authentication module (JWT, Passport)
│ ├── user/ # User module (example)
│ ├── company/ # Company module (example)
├── database/ # TypeORM configuration and entities
├── main.ts # Application entry point
├── app.module.ts # Root module
Swagger documentation is auto-generated and available at /api
. Use it to explore and test API endpoints.
- Fork the project.
- Create a feature branch.
- Commit your changes.
- Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to customize this file further according to your project's specific needs!