CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()pick()Chainable MethodsRefinementsError HandlingSchema Composition
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

| Input | Result | Notes | |---|---|---|---| | true | ✅ true | Actual boolean | | false | ✅ false | Actual boolean | | "true" | ✅ true | Case-insensitive, trimmed | | "false" | ✅ false | Case-insensitive, trimmed | | "TRUE" | ✅ true | Case-insensitive | | "1" | ✅ true | String "1" | | "0" | ✅ false | String "0" | | "yes" | ✅ true | Case-insensitive | | "no" | ✅ false | Case-insensitive | | "on" | ✅ true | Case-insensitive | | "off" | ✅ false | Case-insensitive | | 1 | ✅ true | Number 1 | | 0 | ✅ false | Number 0 | | 2 | ❌ Type error | Only 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 24, 2026

Previousnumber()Nextpick()

On this page

SignatureAccepted ValuesRefinementsExamplesBasic booleanOptional booleanBoolean with defaultCommon patterns