HanifNepali / nestjs_starter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NestJS Starter

NestJS Starter is a boilerplate project for building web applications with NestJS.

Features

  • Modular file structure for improved organization
  • Database interactions using TypeORM with Postgres
  • Authentication using JWT tokens
    • access tokens and refresh tokens methodology
  • Role based authorization
  • Centralized error handling setup
  • Exception filters for HTTP and other types of exception
  • Custom Interceptors for Timeout, Logging etc
  • Custom decorators for Routing, Roles definition etc
  • Custom guards for Authorization
  • Custom Logging services
  • E2E test configuration using sample database using docker container

Prerequisite

  • Node version >= 16

Getting Started

To get started with NestJS Starter, follow these steps:

  1. Clone the repository:
    git clone git@github.com:HanifNepali/nestjs_starter.git
  1. Navigate into the directory:
    cd nest-starter
  1. Install dependencies:
    npm install
  1. Configure environment variables and customize it as needed:

    • Copy the .env.example file to .env.
  2. Start the server:

    npm run start:dev
  1. Visit http://localhost:8000 in your web browser to access the server.

Logger

Built-in logger provided by NestJS has been customized and configured for logging purposes. Please refer to the src/logger folder for more details or visit link for more information.

ORM

TypeORM is used for interacting with the database. Database configuration variables are loaded from the .env file into configuration for typeORM module in the app module. Please refer to the app.module file for more details or visit link for more information.

Error Handling

A centralized error-handling mechanism is set up to catch and log errors. HTTP exceptions are caught in http-exception filter whereas any other exceptions are handled in all-exception filter. Please refer to the filters folder for more details or visit link for more information.

Authentication and Authorization

JWT-based authentication and authorization is implemented where a user is provided access token and refresh tokens for access. These tokens are later used for identity authorization purposes in the application. Please refer to the authentication folder for the detailed implementation.

Testing

A separate database is configured for End-to-End (E2E) testing purposes. Please check the docker-compose.yaml file for the configuration. Built-in testing library provided by - Jest is used for testing purposes. A sample E2E test has been set up for an authentication route. Please refer to the test/auth.e2e-spec file for more details or visit link for more information.

To run E2E tests, please execute the following command:

    npm run test:e2e

To run a specific E2E test, please execute the following command:

    npm run test:e2e -- auth

About


Languages

Language:TypeScript 97.7%Language:JavaScript 2.3%