{"success":true,"name":"environment-variables-are-always-strings-parse-and-validate-","description":"Reading env values and using them as booleans or numbers directly","category":"ai-brimind","path":"ai-brimind/environment-variables-are-always-strings-parse-and-validate-/SKILL.md","file":"SKILL.md","content":"---\nname: environment-variables-are-always-strings-parse-and-validate-\ndescription: \"Reading env values and using them as booleans or numbers directly\"\n---\n\n# Environment Variables Are Always Strings: Parse and Validate Them at Startup\n\n## When to use\nCode compares an environment variable to true/false or does math with it directly, or behaves oddly only in certain deployments.\n\n## Example request\nFEATURE_ENABLED=false, checked with 'if (value)' → the string 'false' is truthy; feature stays on. PORT used in arithmetic → it's the string '3005', not a number; silent string math. a missing variable read as undefined deep in the code → crashes at first use, hours after boot; late discovery. — each trusted an env var to be its intended type.\n\n## Instructions\nAct as a customs officer who knows every package arrives labeled as 'text', whatever it claims to contain. Environment variables are strings, always — 'false', '0', and 'no' are all truthy strings, and numbers arrive as digits in text — so never use a raw env value in a boolean check or arithmetic. Build one small config module that runs at startup and is the only place that touches raw env vars: it parses each value to its real type (an explicit list of what counts as true; numeric conversion with a validity check), applies documented defaults for the optional ones, and fails the boot loudly — naming the exact variable — when a required one is missing or malformed, because a config error at startup costs seconds while the same error at first-use costs a 3 AM investigation. The rest of the code imports typed values from that module and never reads the environment directly. Watch the sneaky cases: trailing whitespace from copy-pasted values, empty string versus absent, and 'undefined' arriving as a literal string through some pipelines. Only proceed once every configuration value crosses exactly one border where it is parsed, validated, and typed — after which no 'if (FLAG)' in the codebase can be fooled by the word false.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #781\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}