Abiral Sthapit
Env Setting File
src/config
├── app
│ ├── app-config.service.ts
│ ├── app-config.controller.ts
│ └── config.ts
└── [...]

Install packages
1. @nestjs/config
2. @hapi/joi
3. @types/hapi_joi

yarn add @nestjs/config @hapi/joi
yarn add -D @types/hapi_joi

Create a .env file in the src of the application and lets assume we have following environment variables.

APP_ENV=dev
APP_NAME=MY APP…

# Source(src) Directory Structure

src
├── auth
├── common
├── config
├── models
├── ... modules
├── jobs
├── providers
├── app.controller.ts
├── app.module.ts
├── app.service.ts
└── main.ts

# Authentication(auth) Directory Structure

https://docs.nestjs.com/security/authenticationsrc/auth
├── strategies
├── guards
├── auth.dto.ts
├── auth.controller.ts
├── auth.service.ts
└── auth.module.ts

# Common(common) Directory Structure

FileName and Indexing

# Class Naming Conventions in NestJS

export class PascalCaseSuffix {} //= pascal-case.suffix.ts
// Except for suffix, PascalCase to hyphen-case
class FooBarNaming {} //= foo-bar.naming.ts
class FooController {} //= foo.controller.ts
class BarQueryDto {} //= bar-query.dto.ts

# Interface Naming Conventions in NestJS

// https://stackoverflow.com/questions/541912
// https://stackoverflow.com/questions/2814805
interface User {}
interface CustomeUser extends User {}
interface ThirdCustomeUser extends CustomeUser {}

# Add Index Exporting

# It is recommended to place index.ts in each folder and export.
# Unless it's a special case, it is import from a folder instead of directly from a file.
- import { FooController } from './controllers/foo.controller';
- import { BarController } from './controllers/bar.controller';
+ import { FooController, BarController } from './controllers';

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store