Skip to content

Configuration

Config in bun-actionhero is statically defined at boot — there's no dynamic config reloading. That said, every config value supports per-environment overrides via environment variables, so you can set things differently in test, development, and production without touching code.

Structure

Config is split into modules:

backend/config/
├── index.ts        # Aggregates everything into one `config` object
├── database.ts     # Database connection string, auto-migrate flag
├── logger.ts       # Log level, timestamps, colors
├── process.ts      # Process name, shutdown timeout
├── redis.ts        # Redis connection string
├── session.ts      # Session TTL, cookie name
├── tasks.ts        # Task queue settings
└── server/
    └── web.ts      # Web server port, host, CORS, static files

Everything rolls up into a single config object:

ts
import { config } from "../config";

config.database.connectionString; // Postgres URL
config.server.web.port; // 8080
config.logger.level; // "info"

Environment Overrides

The loadFromEnvIfSet() helper is where the magic happens:

ts
import { loadFromEnvIfSet } from "../util/config";

export const configDatabase = {
  connectionString: await loadFromEnvIfSet("DATABASE_URL", "x"),
  autoMigrate: await loadFromEnvIfSet("DATABASE_AUTO_MIGRATE", true),
};

The resolution order is:

  1. DATABASE_URL_TEST (env var with NODE_ENV suffix — checked first)
  2. DATABASE_URL (plain env var)
  3. "x" (the default value)

This means you can set DATABASE_URL_TEST=postgres://localhost/bun-test and it'll automatically be used when NODE_ENV=test, without any conditional logic in your config files.

The helper is also type-aware — it parses "true"/"false" strings into booleans and numeric strings into numbers. So DATABASE_AUTO_MIGRATE=false does what you'd expect.

Reference

Database

KeyEnv VarDefault
connectionStringDATABASE_URL"x"
autoMigrateDATABASE_AUTO_MIGRATEtrue

Logger

KeyEnv VarDefault
levelLOG_LEVEL"info"
includeTimestampsLOG_INCLUDE_TIMESTAMPStrue
colorizeLOG_COLORIZEtrue

Redis

KeyEnv VarDefault
connectionStringREDIS_URL"redis://localhost:6379/0"

Session

KeyEnv VarDefault
ttlSESSION_TTL86400000 (1 day in ms)
cookieNameSESSION_COOKIE_NAME"__session"

Process

KeyEnv VarDefault
namePROCESS_NAME"server"
shutdownTimeoutPROCESS_SHUTDOWN_TIMEOUT30000 (30s)

Web Server

KeyEnv VarDefault
enabledWEB_SERVER_ENABLEDtrue
portWEB_SERVER_PORT8080
hostWEB_SERVER_HOST"localhost"
applicationUrlAPPLICATION_URL"http://localhost:8080"
apiRouteWEB_SERVER_API_ROUTE"/api"
allowedOriginsWEB_SERVER_ALLOWED_ORIGINS"*"
staticFilesEnabledWEB_SERVER_STATIC_ENABLEDtrue

Tasks

KeyEnv VarDefault
enabledTASKS_ENABLEDtrue
timeoutTASK_TIMEOUT5000
taskProcessorsTASK_PROCESSORS1

Released under the MIT License.