[NestJS][TypeOrm] Some first note

Desc: Some note when using TypeOrm in NestJS app Active Records vs Data Mapper Patterns In this seriese we gonna use Data Mapper. (It more familiar with other tools, like mongo/mongoose, when it follow the Repository patterns) This post is imported from: https://thebrownbox.hashnode.dev/nestjstypeorm-some-first-note

December 6, 2025 · 1 min

[NestJS] DTO validation

The problem Ví dụ chúng ta có một DTO dưới đây, nếu mà chúng ta ko manual kiểm tra hoặc convert kiểu của các fields này thì payload hoàn toàn có thể có bất kỳ dạng data nào: export class CreateUserDto { username: string; email: string; password: string; isAdmin: boolean; age: number; } The solution DTO validation là việc chúng ta kiểm soát kiểu của dữ liệu đầu vào của API để đảm bảo rằng chúng đúng với format mà chúng ta quy định ở các parameter khác trong handler của chúng ta....

August 18, 2025 · 2 min

Simple .env management with NestJS (with Railway)

I usually deploy my backend in railway. So I usually have only 2 env: local and prod. Create 2 env files: Copy file to .env file in deploy step in package.json Make sure in the PROD deployment we run the correct command (in this case is Railway) Make sure .env file is in .gitignore Note: Variables only load if you install @nestjs/config and import it from AppModule @Module({ imports: [ConfigModule.forRoot()], controllers: [AppController], providers: [AppService], }) export class AppModule {} This post is imported from: https://thebrownbox....

July 20, 2025 · 1 min

Authentication with Supabase Auth + Vue + NestJS [Implicit flow]

Step 1: Google Cloud console settings Link: https://console.cloud.google.com/apis/credentials? You need to have google cloud project. Then go to Clients → OAuth 2.0 Client IDs Add the supabase project url to the origins and redirect urls <PROJECT_ID>.supabase.co Now you have to take note these 2 keys: GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET These keys gonna be used in the next step. Step 2: Supabase Auth settings Go to Authentication → Sign in / Provider. In the Auth Providers list, enable Google Then click to the Google to setup....

July 19, 2025 · 3 min

Setup test local use

Setup path to sync between test and code Setup path for source: tsconfig.json Add this setting to the file to use @src instead of src (the real path) "paths": { "@src/*": ["src/*"] }, full content: { "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "ES2021", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "paths": { "@src/*": ["src/*"] }, "incremental": true, "skipLibCheck": true, "strictNullChecks": false, "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false } } Setup path for test package....

April 3, 2025 · 1 min

Start with a specific file in NestJS

When you want using same code base for multiple services. Create new json file nest-cli-worker.json in the root folder { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "entryFile": "worker-main", "watchAssets": true, "deleteOutDir": true, "compilerOptions": {} } Build is the same but start command is difference package.json "worker:start:dev": "cp env.local.sh .env && nest start --config nest-cli-worker.json --debug --watch", "worker:start:prod": "node dist/worker-main", Note: [_] Note to using difference port if you want to running multiple services at once...

March 4, 2025 · 1 min

Circular Dependency in NestJS

ref: https://docs.nestjs.com/fundamentals/circular-dependency Here I have 2 services that import/inject each other: TransactionsService and FundsService So to able to use both one service in the other, I have to using forwardRef inject. export class TransactionsService { constructor( @Inject(forwardRef(() => FundsService)) private fundService: FundsService ) {} } export class FundsService { constructor( @Inject(forwardRef(() => TransactionsService)) private transService: TransactionsService ) {} }

September 15, 2020 · 1 min