Skip to content
Sign upLog in

.env files not recognised in a bash replit

Profile icon
TheBeast941

I discovered this in another repl, where I would create a .env file and attempt to access variables from it in index.js and it would return "undefined", then I would create a dotenv file and access the varibles from that and the variables would get returned just fine.

After wasting a few hours trying to get it to work, I created a new repl to test what would happen, and this was indeed the behaviour: from index.js using the module "dotenv" with a .env file would return undefined, and using any file other than .env would return the variable, as expected.

Is there any way for the index.js file to be able to read variables from the .env file? (Switching languages from bash to node.js is not an option since this completely breaks the script (the main repl) for some reason)

You are viewing a single comment. View All
Profile icon
TheBeast941

@Coder100

dotenv

dootenv

Here are images showing what I'm trying to explain. First one is using the .env file as the variable file, in which executing the script returns undefined. Second one is using the dotenv file as the variable file, in which exdecuting the file returns the value stored in the variable.

Also, for some reason I have found a workaround to using .env files correctly without them returning as undefined, by simply creating a .replit file and setting the run button to execute "node .". No idea why it works, but it's good enough for me. Also saves me time from having to constantly execute the script from console due to using Javascript in Bash!