CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()semver()pick()ip(), ipv4(), ipv6()uuid(), guid()Chainable MethodsRefinementsError HandlingSchema CompositionSecurityCustom ValidatorswatchEnv()
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

boolean()

Create a boolean validator that parses true/false string values.

  1. Docs
  2. Core API

boolean()

Creates a validator that accepts boolean values. Supports string and numeric coercion.

Signature

function boolean(): BooleanValidator

Accepted Values

InputResultNotes
true✅ trueActual boolean
false✅ falseActual boolean
"true"✅ trueCase-insensitive, trimmed
"false"✅ falseCase-insensitive, trimmed
"TRUE"✅ trueCase-insensitive
"1"✅ trueString "1"
"0"✅ falseString "0"
"yes"✅ trueCase-insensitive
"no"✅ falseCase-insensitive
"on"✅ trueCase-insensitive
"off"✅ falseCase-insensitive
"y"✅ trueShorthand "yes"
"n"✅ falseShorthand "no"
"t"✅ trueShorthand "true"
"f"✅ falseShorthand "false"
1✅ trueNumber 1
0✅ falseNumber 0
2❌ Type errorOnly 1 and 0 are accepted
null❌ Type error

Refinements

boolean() has no type-specific refinements. It only has the chainable methods (.optional(), .default(), .describe(), .secret(), .validate()).

Examples

Basic boolean

const env = defineEnv({
  DEBUG: boolean(),
})
// With process.env.DEBUG = "true"
// env.DEBUG → true

Optional boolean

const env = defineEnv({
  FEATURE_X_ENABLED: boolean().optional(),
})
// env.FEATURE_X_ENABLED: boolean | undefined

Boolean with default

const env = defineEnv({
  ENABLE_LOGGING: boolean().default(true),
})
// env.ENABLE_LOGGING: boolean (defaults to true if not set)

Common patterns

const env = defineEnv({
  // Feature flags
  ENABLE_NEW_DASHBOARD: boolean().default(false),
  SHOW_EXPERIMENTAL: boolean().optional(),

  // Logging controls
  DEBUG: boolean().default(false).describe("Enable debug logging"),
  VERBOSE: boolean().default(false),
})

How is this guide?

Edit on GitHub

Last updated on Jun 30, 2026

Previousnumber()Nextsemver()

On this page

SignatureAccepted ValuesRefinementsExamplesBasic booleanOptional booleanBoolean with defaultCommon patterns