env
ts
import {env} from 'mikro/env'Read environment variables stored in NVS on the device. Provides explicit methods for required vs. optional access, replacing direct import.meta.env property access.
Storage is not encrypted
NVS values are plaintext; anyone with physical access can dump them. See Environment Variables for the full picture.
env.require(key)
ts
env.require(key: string): stringGet a required environment variable. Panics with a clear error message if the variable is not set.
ts
const ssid = env.require('WIFI_SSID')
// TypeError: Required environment variable "WIFI_SSID" is not setUse this for variables your app cannot function without (for example WiFi credentials or API keys).
env.get(key)
ts
env.get(key: string): string | undefinedGet an optional environment variable. Returns undefined if not set.
ts
const debug = env.get('DEBUG')
if (debug) {
console.log('Debug mode enabled')
}env.has(key)
ts
env.has(key: string): booleanCheck whether an environment variable is set.
ts
if (env.has('LOG_LEVEL')) {
// configure logging
}Setting environment variables
See the Environment Variables guide for how to set variables via the CLI, .env files, and secrets.