← Effect fixes your TypeScript

Effect fixes your TypeScript · Part 10

process.env.PORT is string | undefined

· by Tony Tang

Number(process.env.PORT) gives NaN, typos give undefined, and secrets end up in logs. Effect Config validates at startup, redacts secrets, and lets you swap the provider in tests.

Comment below: What's your worst env var incident?

Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website

Transcript

process.env.PORT is string | undefined and you're ignoring it. Number(process.env.PORT): missing? NaN. Typo in the name? undefined. No error. The app boots fine. Then at 3:00 a.m. the first code path that reads the missing key crashes, and your database URL? It just got printed in a log. Password included. In Effect: Config.port("PORT"). It's checked as a real port or the app refuses to start. Config.redacted for secrets. Log it and you get <redacted>, not the password. Defaults are explicit and in tests you swap the config provider. No mutating process.env. Best practice: fail at startup, not at 3:00 a.m. Your app is configured and running, but can you see what it's doing? Part 11, tracing for free. What's your worst env var incident?

Full lesson in the Learn Effect course ↗ Config, the environment with a type

More from this series