Skip to content
Sign upLog in
← Back to Community
Replit's secret (environment variables) not working
Profile icon
Trillionz

I recently noticed .env are no longer allowed in replit with an alternative to use the environment variable secrets.

I tried using that but it never works, i have tried to find a solution online but since it's a new feature I have only seen similar problems without solutions.

How can I go about this..

Voters
Profile icon
VedantNandwana
Profile icon
KendraJackman
Profile icon
ceilingrat
Profile icon
Trillionz
Comments
hotnewtop
Profile icon
Trillionz

Finally found the problem. This new environment variable secrets doesn't work in shell. it returns undefined in shell

Profile icon
Bookie0

You can't make .env files anymore, you'll have to use this new GUI by clicking the lock icon in the sidebar (near where the files are kept). Then you just enter the name of a key and its value. And in the repl, you do import os, and my_secret = os.environ['name of your key here']. Good luck! :)
Screen Shot 2021-04-15 at 8.08.10 PM

Profile icon
Trillionz

@Bookie0
thanks for answering but it seems you don't understand my complain. What you're suggesting is what am complaining that it isn't working

Profile icon
Bookie0

@Trillionz
Ah ok, so what exactly is your problem?

You say:

Replit's secret (environment variables) not working

and

I tried using that but it never works

so what isn't working?

Profile icon
Trillionz

@Bookie0
the secret (environment variable). inserting the secrets in your app as process.env['Token'] is what wasn't working. But i have seen the solution. thanks

Profile icon
Bookie0

@Trillionz
ah hum okay then. :)

Profile icon
RakoGames

@Trillionz
what is it?

Profile icon
PeterChmiel1

@Trillionz
So what is the solution for using secret with javascript? process.env['Token'] does not work for me either.

Profile icon
Trillionz

@PeterChmiel1
It works when you run it on the console. It will return undefined if you run it on shell

Profile icon
LeoXu2

shuld be here
image

Profile icon
Vandesm14

Use the secrets button on the sidebar. More info here: https://docs.replit.com/repls/secrets-environment-variables