Skip to main content

Documentation 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.

KaroKar Backend reads all runtime configuration from a single .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.
cp .env.example .env
The example file ships with safe defaults for local development:
NODE_ENV=development
PORT=3000

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/karokar

JWT_SECRET=change-me-in-production
Never use the default JWT_SECRET value in a non-development environment. The string change-me-in-production is publicly committed to the repository. Any JWT signed with it can be forged by anyone who has read the source code. Replace it with a cryptographically random secret before deploying.
Generate a strong secret with openssl rand -base64 48 and store it in your organisation’s secret manager (AWS Secrets Manager, HashiCorp Vault, Doppler, etc.). Inject it into the runtime environment rather than committing the real value to .env in version control.

Environment Variables

NODE_ENV
string
required
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: development
PORT
number
required
The 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: 3000
DATABASE_URL
string
required
A full PostgreSQL connection string. The application calls configService.getOrThrow<string>('DATABASE_URL'), which means the process will crash at startup if this variable is missing. Format:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE
Example: postgresql://postgres:postgres@localhost:5432/karokar
JWT_SECRET
string
required
The 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:
ConfigModule.forRoot({
  isGlobal: true,
  envFilePath: '.env',
}),
OptionValueEffect
isGlobaltrueRegisters 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.
app.useGlobalPipes(
  new ValidationPipe({
    whitelist: true,
    forbidNonWhitelisted: true,
    transform: true,
  }),
);
OptionBehaviour
whitelist: trueStrips any properties that are not declared with a decorator in the target DTO class. Unknown fields are silently removed.
forbidNonWhitelisted: trueEscalates the whitelist check from silent removal to a 400 Bad Request error. The response includes the names of the offending properties.
transform: trueAutomatically 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:
const configService = app.get(ConfigService);
const port = configService.get<number>('PORT', 3000);

await app.listen(port);
The fallback value 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.

Build docs developers (and LLMs) love