Use .env variables in Jest & NodeJS testing

Matthias Orgler
2 min readDec 11, 2020
Photo by Clément H on Unsplash

If you want to test a a NodeJS application with Jest, you often need to set local environment variables. Usually these variables are set on the server when deploying your application, but they’re not available locally for testing.

A common pattern is to use a .env file with all variables for local development and testing. However, to load these variables before you run your test can be…

--

--

Matthias Orgler

Agile Coach, Business Innovator, Software Engineer, Musician