KaroKar Backend reads all runtime configuration from a singleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Codefied-CodePix/Karokar-backend/llms.txt
Use this file to discover all available pages before exploring further.
.env file at the project root. The file is loaded once at bootstrap by @nestjs/config’s ConfigModule, which is registered with isGlobal: true — meaning every NestJS module in the application can inject ConfigService without importing ConfigModule locally. Alongside environment variables, the bootstrap function in src/main.ts applies a strict ValidationPipe globally so that every incoming HTTP request is validated, sanitized, and transformed before it reaches a controller.
Quick Start
Copy the provided example file and fill in the values for your environment before running the application.Environment Variables
Controls the runtime environment mode. Accepted values are
development and
production. NestJS and its ecosystem libraries use this value to toggle
behaviour such as detailed error messages, query logging, and optimization
flags.Default: developmentThe TCP port on which the NestJS HTTP server listens. Resolved inside
src/main.ts via configService.get<number>('PORT', 3000) — the second
argument is the fallback when the variable is absent.Default: 3000A full PostgreSQL connection string. The application calls
Example:
configService.getOrThrow<string>('DATABASE_URL'), which means the process
will crash at startup if this variable is missing. Format:postgresql://postgres:postgres@localhost:5432/karokarThe symmetric secret used by
@nestjs/jwt to sign and verify JSON Web Tokens.
Must be a long, random, unpredictable string in all non-development
environments.How Configuration Is Loaded
ConfigModule is registered in AppModule with two options:
| Option | Value | Effect |
|---|---|---|
isGlobal | true | Registers the module globally so every feature module can inject ConfigService without re-importing ConfigModule. |
envFilePath | '.env' | Instructs the module to read the .env file located at the project root. |
Global ValidationPipe
src/main.ts attaches a single ValidationPipe instance to the entire
application using app.useGlobalPipes(...). Every request body, query
parameter, and route parameter is processed through this pipe before it reaches
a controller method.
| Option | Behaviour |
|---|---|
whitelist: true | Strips any properties that are not declared with a decorator in the target DTO class. Unknown fields are silently removed. |
forbidNonWhitelisted: true | Escalates the whitelist check from silent removal to a 400 Bad Request error. The response includes the names of the offending properties. |
transform: true | Automatically transforms the plain request payload into an instance of the declared DTO class, and coerces primitive types (e.g. converts the string "3000" in a query param to the number 3000) when the DTO declares the correct type. |
transform: true depends on class-transformer being installed, which is
already listed as a dependency in package.json. The reflect-metadata
polyfill imported at the top of main.ts is required for TypeScript decorator
metadata to function correctly at runtime.Server Startup
After the pipe is registered, the application binds to the resolved port:3000 in configService.get means the server will always
start even if PORT is absent from .env, making local development slightly
more forgiving while still allowing the port to be overridden in CI or
container deployments via an environment variable.