Skip to content

.tip

· one of the small things

node --env-file replaces dotenv

You don't need a package to load a .env file any more. Node reads it before your code runs, so there's no import to keep at the top of the entry file.

node --env-file=.env server.js
node --env-file-if-exists=.env.local --import tsx scripts/sync.ts

--env-file arrived in 20.6 and --env-file-if-exists in 22.9. The second is what you want for an optional local override, because a missing file isn't an error. It reads KEY=value and quoted values without expanding $OTHER, so keep those references out of the file.

nodejstooling