Can't access Variables from Railway
meraj-sharif-khan
TRIALOP

a year ago

My MONGODBURI key is in .env file. if i set this key in railway variables i cant access this through process.env.MONGODBURI.
i don't want to push my (if i push .env to my project then its work) .env in GitHub repo . i want to access my key via railway variables but its not working , i don't know why. 😭

Solved

41 Replies

smoothcubegit
HOBBY

a year ago

Normally you use OS and dotenv

then do

from dotenv import load_dotenv
import os

load_dotenv()

pgdatabaseurl = os.getenv("DATABASE_URL")

For example ^

(This is obviously python)


smoothcubegit
HOBBY

a year ago

The env is also in the root of the directory for simple code


meraj-sharif-khan
TRIALOP

a year ago

232f447d-05a8-4850-b9a6-0dc96c65800f


meraj-sharif-khan
TRIALOP

a year ago

while deploying my project variable that i set in railway is undefine why. (should i hard code my key or should i push my .env file only these tow way is working and this is not ideal thing to do)

1342145295445790700
1342145295739256800
1342145296066543600


smoothcubegit
HOBBY

a year ago

Really, to keep it safe, i would recommend putting your key in a .env

May i ask what coding language you are using?


meraj-sharif-khan
TRIALOP

a year ago

js


smoothcubegit
HOBBY

a year ago

Oh. Brody disagrees, alright sure… :(((


smoothcubegit
HOBBY

a year ago

I’ll just cry in a corner


a year ago

in their original screenshot you can see the variable is highlighted in blue(?), that means they have not deployed the changes yet


smoothcubegit
HOBBY

a year ago

AH!


smoothcubegit
HOBBY

a year ago

Also if you get time do you mind helping with my issue afterwards?


meraj-sharif-khan
TRIALOP

a year ago

how will its look when the variables is set


a year ago

no blue(?) highlight


a year ago

do you see a "Deploy changes" button in a floating popup in your screen?


a year ago

Deploy *


meraj-sharif-khan
TRIALOP

a year ago

1342147323622326500


meraj-sharif-khan
TRIALOP

a year ago

i have been redeploying it again and again , and done all the troubleshooting but my project is not accessing the variable from railway. railway not injecting the variable.


smoothcubegit
HOBBY

a year ago

The purple button at the top says deploy


a year ago

ah purple


smoothcubegit
HOBBY

a year ago

Also it crashed? So the code is incorrect? I know a tiny bit lel


meraj-sharif-khan
TRIALOP

a year ago

every thing is working 😆 now


smoothcubegit
HOBBY

a year ago

Amazing <:salute:1137099685417451530>


meraj-sharif-khan
TRIALOP

a year ago

crashed because of db connection variable was not injecting.


smoothcubegit
HOBBY

a year ago

Also just as a reference you can private your github repo, as railway deploys from privates


smoothcubegit
HOBBY

a year ago

Ah


meraj-sharif-khan
TRIALOP

a year ago

its privet .


meraj-sharif-khan
TRIALOP

a year ago

i was learning how to set variable without pushing .env in my repo


smoothcubegit
HOBBY

a year ago

Just make sure you dont have the variables in plaintext in the script if you are hardcoding it


smoothcubegit
HOBBY

a year ago

Im using a .env, however we all do things differently


meraj-sharif-khan
TRIALOP

a year ago

that is the point (i have set key only in railway variable and accessing it via process.env) its not hard coadded nor i have pushed my .env its safe(little bit) now


a year ago

smooth, locally only I hope?


smoothcubegit
HOBBY

a year ago

Y-y-yea-eah…


smoothcubegit
HOBBY

a year ago

I d-d-def-initely do..


smoothcubegit
HOBBY

a year ago

Not at all in production


smoothcubegit
HOBBY

a year ago

What do you mean???


meraj-sharif-khan
TRIALOP

a year ago

it was the button that i have not pushed (deploy) every thing was fine. i was redeploying it again and again. <:kekw:788259314607325204> 😆

1342151844553822200


smoothcubegit
HOBBY

a year ago

Its all good! Now you have learnt <:poggers:720701334659268700>
took me some time as well


smoothcubegit
HOBBY

a year ago

Variables stored in railway’s environment variable section, not in github


meraj-sharif-khan
TRIALOP

a year ago

thanks @Smooth Cube @Brody @Medim


smoothcubegit
HOBBY

a year ago

<:bufo_salute:1335306892578263070>


a year ago

!s


Status changed to Solved brody • about 1 year ago


Loading...