.env not loaded locally after git clone

How does glitch load .env file on project start? My .env file is not picked up after I git clone the project. I had to add require('dotenv').config() to server.js. This seems to work fine on glitch as well. Is this the best way to consistently pick up environment variables? Thank you.

Do you mean that your .env file is not copied into your Glitch project with git clone or do you mean your cloned environment variables are not accessible in your code?

If it’s the former it’s most likely because .env files are .gitignore-ed by default, but if it’s the latter someone with more Node knowledge than myself may be able to help…

Thank you. I understand the .env will not be downloaded for security reasons. I meant the second. Glitch is doing something to read the .env automatically without me having to code it explicitly. I can do so by using dotenv locally. That does not affect the code on glitch. Wondering if there is a better way.

Oh yeah, that’s by design. Glitch automatically adds all entries in the .env file into the execution environment as true environment variables. That means you can access them directly rather than via the .env file.

So in Node thats something like process.env.VARIABLE or in Python something like os.enviorn['VARIABLE']. In both cases you don’t need an external dependency.

1 Like

Right. I get that part. The same code fails locally because the magic does not happen automatically. So I am using dotenv and pushing the same code back on glitch. I guess that’s okay as it works.

Thank you for your time.