Skip to content
.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 Ah, so running "node . " in console means the script won't see the .env file, but running the command with the run button allows the script to see the .env file?