Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tonidarodda/nestjs-template

NestJS template for projects with TypeOrm, featuring account management, authentication, emailing, caching, compression, scheduled tasks, and S3.
https://github.com/tonidarodda/nestjs-template

caching compression emailing nest nestjs nestjs-backend s3 swagger tasks template template-project typeorm websocket

Last synced: 3 months ago
JSON representation

NestJS template for projects with TypeOrm, featuring account management, authentication, emailing, caching, compression, scheduled tasks, and S3.

Awesome Lists containing this project

README

        

---

# NestJS Template

![NestJS](https://img.shields.io/badge/NestJS-7E1E9C?style=for-the-badge&logo=nestjs&logoColor=white)
![TypeORM](https://img.shields.io/badge/TypeORM-FF7A59?style=for-the-badge&logo=typeorm&logoColor=white)
![PostgreSQL](https://img.shields.io/badge/PostgreSQL-336791?style=for-the-badge&logo=postgresql&logoColor=white)
![PNPM](https://img.shields.io/badge/PNPM-4D4D4D?style=for-the-badge&logo=pnpm&logoColor=white)
![License](https://img.shields.io/badge/License-LICENSED-green?style=for-the-badge)

This project is a NestJS template that includes various features such as user account management, authentication, authorization, email integration, caching, compression, centralized error handling, input validation, logging, scheduled tasks, and file upload to S3.

## Features

- ๐Ÿ‘ค **User Account Management**
- Sign-up, Sign-in, Get user, Update user, Delete user
- ๐Ÿ” **Authentication and Authorization**
- JWT-based authentication, role-based authorization
- โœ‰๏ธ **Email Integration**
- Send emails using Nodemailer
- ๐Ÿ’พ **Caching**
- Optimize responses for frequently requested endpoints
- โŒ **Centralized Error Handling**
- Global exception filter to handle all errors consistently
- โœ… **Input Validation**
- Validate user inputs using class-validator
- ๐Ÿ““ **Logging**
- Log application activities and errors
- ๐Ÿ—‚ **Compression**
- Compress HTTP responses to improve performance
- โฐ **Scheduled Tasks**
- Perform periodic tasks using CRON jobs
- ๐Ÿ“ค **File Upload to S3**
- Upload and retrieve files from Amazon S3

## ๐Ÿš€ Getting Started

### Prerequisites

- Node.js (v14 or higher)
- PostgreSQL
- Email service credentials (e.g., Gmail SMTP)
- AWS S3 credentials for file upload

### Installation

1. Clone the repository

```sh
git clone https://github.com/ToniDarodda/NestMonolithTemplate.git
cd NestMonolithTemplate
```

2. Install dependencies

```sh
pnpm install
```

3. Update the `.env` file in the root directory and configure environment variables:
```sh
EMAIL_PASS='Your password'
```

### Running the Application

1. Start the PostgreSQL database

2. Run the application

```sh
pnpm run start:dev
```

3. The API will be available at `http://localhost:3000`

### API Documentation

The API documentation is available at `http://localhost:3000/api`.

## ๐Ÿ“„ Usage

### User Account Management

- **๐Ÿšช Sign Up**

```http
POST /account/sign-up
```

Request Body:

```json
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "1234567890",
"password": "password",
"country": "USA"
}
```

- **๐Ÿ”‘ Sign In**

```http
POST /account/sign-in
```

Request Body:

```json
{
"email": "[email protected]",
"password": "password"
}
```

- **๐Ÿ‘ค Get User Information**

```http
GET /account
```

Requires JWT Authentication and User Role

- **๐Ÿ“ Update User Information**

```http
PATCH /account
```

Requires JWT Authentication and User Role

Request Body:

```json
{
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "1234567890",
"country": "USA"
}
```

- **๐Ÿ—‘๏ธ Delete User Account**

```http
DELETE /account
```

Requires JWT Authentication and User Role

### File Upload to S3

- **๐Ÿ“ค Upload File**

```http
POST /file/upload
```

Requires JWT Authentication

Request Body: Form-data with `file` field

- **๐Ÿ“ฅ Get File**

```http
GET /file/:fileName
```

Requires JWT Authentication

## ๐Ÿงช Testing

To run the tests, use the following command:

```sh
pnpm run test
```

## ๐Ÿ› ๏ธ Scripts

- `๐Ÿ”จ build`: Build the application
- `๐Ÿงน format`: Format the code using Prettier
- `๐Ÿƒโ€โ™‚๏ธ start`: Start the application
- `๐Ÿ‘จโ€๐Ÿ’ป start:dev`: Start the application in development mode
- `๐Ÿž start:debug`: Start the application in debug mode
- `๐Ÿš€ start:prod`: Start the application in production mode
- `๐Ÿ” lint`: Lint the code using ESLint
- `๐Ÿงช test`: Run the tests
- `๐Ÿ“ฆ migration:generate`: Generate a new database migration
- `๐Ÿšš migration:run`: Run the database migrations
- `๐Ÿ•ต๏ธโ€โ™‚๏ธ test:watch`: Run the tests in watch mode
- `๐Ÿ“Š test:cov`: Run the tests and generate coverage report
- `๐Ÿ› test:debug`: Run the tests in debug mode
- `๐Ÿงช test:e2e`: Run end-to-end tests

## ๐Ÿ“œ License

This project is licensed under the UNLICENSED License.

## ๐Ÿ‘ค Author

[Toni Da Rodda](mailto:[email protected])

## ๐Ÿ› ๏ธ Icons

- ๐Ÿš€ Deployment
- โš™๏ธ Configuration
- ๐Ÿ“„ Documentation
- ๐Ÿ”ง Maintenance
- ๐Ÿ”’ Security
- ๐Ÿ“ซ Email Integration
- ๐Ÿ“ˆ Performance Optimization
- โšก Gain Time

---

Feel free to contribute to this project by submitting issues or pull requests.

For any questions or support, please contact [Toni Da Rodda](mailto:[email protected]).

---