I've lost count of how many times I've seen this in production:
const port = parseInt(process.env.PORT || "3000", 10)
const dbUrl = process.env.DATABASE_URL
if (!dbUrl) throw new Error("DATABASE_URL is required")
Enter fullscreen mode
process.env is a string-typed wasteland. Here's a zero-dependency library that fixes it without the bloat.
I've lost count of how many times I've seen this in production:
const port = parseInt(process.env.PORT || "3000", 10)
const dbUrl = process.env.DATABASE_URL
if (!dbUrl) throw new Error("DATABASE_URL is required")
Enter fullscreen mode

TL;DR — process.env.PORT is a string | undefined, your bundler silently inlines client env at build...

process.env gives you string | undefined and calls it a day. Here's why that's dangerous and how to fix it.

Every Node.js project I've ever worked on has the same invisible vulnerability. Somewhere in the...

Number(process.env.PORT) || 3000 That line shows up in a lot of config files, and it has two bugs...

Configuring environment variables seems simple, but it frequently leads to two common issues in...

Environment variables look simple until one of them is missing, empty, malformed, or interpreted in a...