DEV Community

Andreas Bergström
Andreas Bergström

Posted on • Edited on • Originally published at andreasbergstrom.dev

How to make VS Code read dotenv file when debugging

When VS Code's JS debugger refuses to pick up the environment variables your app reads via dotenv, the instinct is to wedge -r dotenv/config into the launch command. That works, but it's the wrong lever — VS Code already has a first-class hook for this, and it's a single line in launch.json.

The full post shows the minimal Node launch configuration with the envFile attribute pointing at ${workspaceFolder}/.env, why this beats the -r dotenv/config workaround, and links the upstream PR I opened against the VS Code docs to make this discoverable next to the more common launch examples.


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (3)

Collapse
 
ramonmedeiros profile image
Ramon Medeiros

Thanks

Collapse
 
andreasbergstrom profile image
Andreas Bergström

Hope this still works!