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

number()

Create a number validator with port, min, max, integer, and float checks.

  1. Docs
  2. Core API

number()

Creates a validator that accepts number values. Also accepts numeric strings (coerces to number).

Signature

function number(): NumberValidator

Accepted Values

InputResultNotes
42✅ 42Actual number
"42"✅ 42Numeric string, coerced
"3.14"✅ 3.14Float string, coerced
""❌ Type errorEmpty string
"abc"❌ Type errorNon-numeric
NaN❌ InvalidNon-finite
Infinity❌ InvalidNon-finite
true❌ Type errorBoolean
null❌ Type errorNot a number

Refinements

.int()

Requires the number to be an integer:

const env = defineEnv({
  MAX_CONNECTIONS: number().int(),
})
// ✅ 10
// ❌ 10.5
// ❌ "10.5"

.positive()

Requires the number to be greater than zero:

const env = defineEnv({
  RATE_LIMIT: number().positive(),
})
// ✅ 1
// ✅ 100
// ❌ 0
// ❌ -5

.port()

Requires the number to be a valid port (1-65535, integer):

const env = defineEnv({
  PORT: number().port(),
})
// ✅ 3000
// ✅ 65535
// ❌ 0
// ❌ 70000
// ❌ 3000.5

.min(value)

Requires the number to be greater than or equal to value:

const env = defineEnv({
  WORKERS: number().min(1),
})
// ✅ 1
// ✅ 4
// ❌ 0

.max(value)

Requires the number to be less than or equal to value:

const env = defineEnv({
  TIMEOUT: number().max(30000),
})
// ✅ 5000
// ✅ 30000
// ❌ 35000

Chaining

number().int().positive().min(1).max(100).default(50)
number().port()
number().min(0).optional()

Examples

Basic number

const env = defineEnv({
  MAX_RETRIES: number().int().min(0).max(10).default(3),
})
// env.MAX_RETRIES: number (default: 3)

Number with coercion

const env = defineEnv({
  PORT: number().port(),
})
// With process.env.PORT = "4000"
// env.PORT → 4000 (coerced from "4000")

Optional number

const env = defineEnv({
  CACHE_TTL: number().positive().optional(),
})
// env.CACHE_TTL: number | undefined

How is this guide?

Edit on GitHub

Last updated on Jun 24, 2026

Previousstring()Nextboolean()

On this page

SignatureAccepted ValuesRefinements.int().positive().port().min(value).max(value)ChainingExamplesBasic numberNumber with coercionOptional number