NOTE: Starting April 18,2022 , the repo has ditched most promises for observables. You can check the latest promised version code at [commit](https://github.com/rubiin/ultimate-nest/tree/fb06b34f7d36f36195880e600f8f1b5b86f71213)
NodeJS https://nodejs.org/en/
Typescript https://www.typescriptlang.org/
PostgresQL https://www.postgresql.org/
Redis https://redis.io/
RabbitMQ https://www.rabbitmq.com
Clone this repo. Edit the env file and pass in your credentials
Install dependencies (preferred: pnpm)
npm install --legacy-peer-deps
yarn install
pnpm install --shamefully-hoist=true
The example codebase uses MikroORM with a Postgres database.
Copy sample env file and adjust the connection settings and other settings(jwt,redis,mail,etc) respectively on sample env file
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
Start local Postgres server and run NODE_ENV=dev make migrate
to apply migrations
Now you can start the application witt NODE_ENV=dev npm run start
.
Note: If you are using windows, SET NODE_ENV=dev npm run start
- ๐ I18n - Internationalization
- ๐งต Stats - swagger stats for common server metrics
- ๐งต Poolifier - threads for cpu extensive tasks
- ๐ฌ Twillio - sms support
- ๐ฑ NestJS โ latest version
- ๐ TypeScript - Type checking
- โ๏ธ Dotenv - Supports environment variables
- ๐ Authentication - 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
- ๐ด Insomnia - Insomnia config for endpoints
- ๐ ESLint โ Pluggable JavaScript linter
- ๐ Prettier - Opinionated Code Formatter
npm run start
- Start applicationnpm run start:dev
- Start application in watch modenpm run test
- run Jest test runnernpm run start:prod
- Build application
Additionally, you can also see the scripts in makefile
- First if you don't want to use any libs from like redis, mailer etc. replace them from the app.module.tasks
- 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
- Make sure you create a env file under
env
directory with name like.env.something
.The portion after .env is theNODE_ENV
value which will be required while running the app - Also make sure you have ssl files inside
src/resources/ssl
if you tend to use ssl. Replace the sample files with your ssl files but keep the name same. Additionally
Migrations are used to update the database schema. The migration files are stored in migrations
directory.
env=dev make migrate # applies migration for dev env
Seeding is used to insert data into the database. The seeding files are stored in common/database/seeders
directory.
env=dev make seed # seeds data for dev env with user password set as Test@1234
NODE_ENV=[env name] npm run start
(without ssl)NODE_ENV=[env name] SSL=true npm run start
(with ssl)- Test api by browsing to
http://localhost:[port]/v1/user
- 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 `yarn test:cov` command.
โโโ dist * Optimized code for production after `yarn 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
(not the compose plugin) installed. Also since we are using makefiles
for deployment, you need to have make
installed.
env=dev make deploy # deploys dev environment (.env.dev used)
env=prod make deploy # deploys prod environment (.env.prod used)
The password for redis
and rabbitmq
is Test@1234
can be changed in the make file under deploy
script
The sample env is generated using sample-env
More docs found at docs
folder