This document describes the environment configuration setup for the Expense Tracker Backend application.
The application supports multiple environments:
- Development: Local development environment
- Staging: Pre-production testing environment
- Production: Live production environment
The application uses environment-specific configuration files:
.env.development
- Development environment settings.env.staging
- Staging environment settings.env.production
- Production environment settings.env
- Default fallback settings
The following configuration options are available in the environment files:
PORT
- The port the server will listen onHOST
- The host address to bind toNODE_ENV
- The environment mode (development, staging, production)
DATABASE_URL
- The connection string for the database
LOG_LEVEL
- The logging level (debug, info, warn, error)
API_PREFIX
- The prefix for API routes
# Server Configuration
PORT=3000
HOST=localhost
NODE_ENV=development
# Database Configuration
DATABASE_URL="postgresql://postgres:password@localhost:5432/expense_tracker_dev"
# Logging
LOG_LEVEL=debug
# API Configuration
API_PREFIX=/api
The application provides scripts for running in different environments:
# Run in development mode
pnpm dev
# Run in staging mode
pnpm dev:staging
# Run in production mode
pnpm dev:prod
# Build the application
pnpm build
# Start in development mode
pnpm start:dev
# Start in staging mode
pnpm start:staging
# Start in production mode
pnpm start:prod
The environment configuration is managed by the src/config/environment.ts
file, which:
- Loads the appropriate
.env
file based on theNODE_ENV
environment variable - Provides a typed interface for accessing configuration values
- Handles fallbacks for missing values
You can access the configuration in your code using:
import config from '@config/index';
// Access configuration values
const { port, host } = config.server;
const { url } = config.database;