NOTE: Starting April 18,2022 , the repo has ditched most promises for observables. You can check the latest promised version code at commit
More on why observables are better than promises can be read here
- Whats included
- Prerequisites
- Getting Started
- Available Scripts
- Setup
- File Structure
- Authentication
- Deployment
- π I18n - Internationalization
- 𧡠Stats - Swagger stats for common server metrics
- 𧡠Poolifier - Threads for CPU extensive tasks
- π¬ Twilio - SMS support
- π± NestJS β Latest version
- π TypeScript - Type checking
- βοΈ Dotenv - Supports environment variables
- π Authentication, RSA256, [OAuth](https://oauth.net/ - JWT, RSA256, OAuth
- π¬ Authorization - RBAC with casl
- πͺ MikroORM - Database ORM
- πͺ PostgreSQL - Open-Source Relational Database
- π§ Configuration - Single config for all
- π Swagger - API Documentation
- π³ Docker Compose - Container Orchestration
- π Helmet - Secure HTTP headers
- π ESLint β Pluggable JavaScript linter
- β Commitlint β Checks if your commit messages meet the conventional commit format.
- πΊ Husky β Helps you create Git hooks easily.
NodeJS https://nodejs.org/en/
Typescript https://www.typescriptlang.org/
PostgresQL https://www.postgresql.org/
Redis https://redis.io/
RabbitMQ https://www.rabbitmq.com
# 1. Clone the repository or click on "Use this template" button.
npx degit rubiin/ultimate-nest my-nest-app
# 2. Enter your newly-cloned folder.
cd ultimate-nest
# 3. Create Environment variables file.
cp env/.env.sample env/.env.dev
# 4. Install dependencies (preferred: pnpm)
pnpm install
npm install
yarn install
Note
If you face any issues with dependencies when using yarn or npm, stick to pnpm for now
Note
Env files are kept in env folder. The config validation allows 4 environment ['dev', 'prod', 'test','stage']. The env file name should be of format .env.[environment] Ex. (.env.dev). The env to use should be provided while running any script as NODE_ENV=dev npm run dev
npm run start
- Start applicationnpm run start:dev
- Start application in watch modenpm run start:prod
- Start built applicationnpm run start:hmr
- Start application with hot module replacementnpm run lint
- Uses eslint to lint all the files inside src with config provided ineslint.config.js
npm run orm migration:create
- Uses Mikroorm to create a migration filenpm run orm migration:up
- This command is used to run availablexisting migration files.npm run orm migration:down
- This command is used to rollback migration.npm run orm seeder:run
- This command is used to run existing seeders insrc/common/database
.
All the scripts require NODE_ENV
flag
Additionally, you can also see the scripts in justfile
which is a cross platform task runner. You can use it by
installing just and then running just <script>
. Ex. just build
- First if you don't want to use any libs from like redis, mailer etc. replace them from the config.module.ts
- You will also need to remove the config from
validate.config.ts
from lineload: []
- Also remove the unwanted config variables from the env file
- You will also need to remove the config from
Migrations are used to update the database schema. The migration files are stored in migrations
directory.
NODE_ENV=dev npm run orm migration:up # applies migration for dev env
Seeding is used to insert data into the database. The seeding files are stored in common/database/seeders
directory.
USER_PASSWORD=Test@1234 NODE_ENV=dev npm run orm seeder:run # seeds data for dev env with all user password set as Test@1234
Seeding is optional
NODE_ENV=dev npm run start
- View automatically generated swagger api docs by browsing to
http://localhost:[port]/docs
- View automatically generated swagger stats dashboard by browsing to
http://localhost:[port]/stats
. The username and password is the values set in the env file underSWAGGER_USERNAME
andSWAGGER_PASS
respectively
ultimate-nest
βββ env * Contains all configuration files
β βββ .env.example * Sample configuration file.
β βββ .env.dev * Configuration file for development environment.
β βββ .env.prod * Configuration file for production environment.
β βββ .env.test * Configuration file for test environment.
βββ coverage * Coverage reports after running `npm run test:cov` command.
βββ dist * Optimized code for production after `npm run build` is run.
βββ src
βββ modules * Folder where specific modules all files are stored
βββ <module>
β βββ dto * Data Transfer Objects.
β βββ <module>.controller.ts * Controller file.
β βββ <module>.module.ts * root module file for module.
β βββ <module>.service.ts * Service file for <module>.
β βββ <module>.service.spec.ts * Test file for service.
β βββ <module>.repository.ts * Repository file for <module>.
β βββ <module>.repository.spec.ts * Test file for repository.
β βββ common * Common helpers function, dto, entity,guards, custom validators,types, exception, decorators etc.
β βββ __mocks__ * Fixtures for unit tests.
β βββ libs * Resusable pre configured libraries
β βββ resources * Contains all static resources like ssl, i18n,email templates etc.
β βββ app.module.ts * Root module of the application.
β βββ main.ts * The entry file of the application which uses the core function NestFactory to create a Nest application instance.
βββ test * End to end test files for the application.
This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using
the Authorization
header with Token
scheme. The JWT authentication middleware handles the validation and
authentication of the token.
You need to have docker
and docker-compose
installed. The image environment variable values can be found at the compose file
ENV=dev sh ./scripts/deploy.sh # deploys dev environment (.env.dev used)
ENV=prod sh ./scripts/deploy.sh # deploys prod environment (.env.prod used)
More docs found at docs
folder
Also if you are into NestJS ecosystem you may be interested in one of my other libs:
A collection of helper functions for typescrip development. It includes functions for array,object,string,etc
Platform config manager for nestjs. It supports multiple config files and environment variables.
This is a minio module for Nest.
This is a cloudinary module for Nest.
A Module for Utilizing Pg-promise with NestJS
Made with β€οΈ with opensource.