.env file in the API root directory.
Environment variables
Create a.env file based on .env.example with the following variables:
Database
PostgreSQL connection string for the database.
The connection string follows the format:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMAAuthentication
Secret key used for signing and verifying JWT tokens.
External APIs
The backend integrates with several aviation data providers:API key for Aviation Stack, used to fetch flights between two airports for a given date.Get your API key at Aviation Stack
API key for RapidAPI’s AeroDataBox service, used for detailed flight and aircraft information.Subscribe to AeroDataBox on RapidAPI to get your API key.
API key for FlightAware, used for real-time flight tracking and position data.Register at FlightAware to get your API key.
Server
Port number for the API server.If not specified, defaults to port 5000.
NestJS configuration
The backend uses@nestjs/config for configuration management. Configuration is loaded globally in app.module.ts:
src/app.module.ts
Accessing configuration
InjectConfigService to access environment variables in your services:
CORS configuration
CORS is enabled globally inmain.ts to allow cross-origin requests:
src/main.ts
Validation
Global validation is configured usingclass-validator and class-transformer:
src/main.ts
Validation options
- whitelist: Strip properties that don’t have decorators
- transform: Automatically transform payloads to DTO instances
- enableImplicitConversion: Automatically convert types based on TypeScript metadata
API versioning
The API uses URI versioning with a default version ofv1:
src/main.ts
/v1/ by default.
Logging
The backend uses Morgan for HTTP request logging in development mode:src/main.ts
Prisma configuration
Prisma is configured with enhanced error formatting and logging:src/db/index.ts
Preview features
The Prisma schema enables these preview features:prisma/schema.prisma
- fullTextSearchPostgres: Enables PostgreSQL full-text search
- omitApi: Allows omitting fields when querying
Security
Helmet
The backend includes Helmet for security headers:Password hashing
Passwords are hashed using Argon2, a secure password hashing algorithm:Static file serving
The backend serves static files from theweb directory:
src/app.module.ts
Example .env file
Here’s a complete example of a.env file:
.env
Replace all placeholder values with your actual credentials before running the application.