anybody knows how to fix? I have put all the varaibles in already

No description
19 Replies
Percy
Percy11mo ago
Project ID: N/A
Fragly
Fragly11mo ago
Railway doesn't create .env files, they throw the service variables as environment variables into the docker container they create for your project
maddsua
maddsua11mo ago
To me it looks like it tries to read .env file which is not present in the repo. This is expected, you should add your variables using the dashboard
Bilal Ahmad
Bilal Ahmad11mo ago
i have added the variables in the dashboard already
Fragly
Fragly11mo ago
Yes, railway won't create a .env file for those variables
Bilal Ahmad
Bilal Ahmad11mo ago
then how to access them in code?
maddsua
maddsua11mo ago
in this case you need to removed the logic responsible for grabbing that file from your app
Bilal Ahmad
Bilal Ahmad11mo ago
any way we can make railway to create .evn file?
maddsua
maddsua11mo ago
you access env vars with process.env.ENV_NAME if it's node, I assume it is
Fragly
Fragly11mo ago
const port = process.env.PORT || 3000
const port = process.env.PORT || 3000
Bilal Ahmad
Bilal Ahmad11mo ago
yes that's exactly how I am accessing them right now
maddsua
maddsua11mo ago
so the problem is just that the app tries to load .env anyway? I can't see your code but I expect there to be a line that needs to be disabled when the app is run on railway
Bilal Ahmad
Bilal Ahmad11mo ago
@maddsua Nope, actually I do have a config service setup in the nest js that loads env file and expose all varaibles in the code
Fragly
Fragly11mo ago
Yea you don't want it to load the .env file in production on railway
maddsua
maddsua11mo ago
yeah, dotenvs are kinda a hacky way of having env variables on local machine, they're not meant to be used on servers. mainly because of the security considerations
Bilal Ahmad
Bilal Ahmad11mo ago
@maddsua Will have to eliminate config service then and use variables using dot env I believe
maddsua
maddsua11mo ago
maybe there's an option to disable in case of certain variable already present?
Brody
Brody11mo ago
well the problem is you are treating the missing .env file as a fatal error, there's nothing wrong with running dotenv.load but just don't treat the missing .env as a fatal error and you'd be good
ThallesComH
ThallesComH11mo ago
place a try catch around the code that loads the .env and ignore it (or console.warn saying that you couldn't load the .env file)
Want results from more Discord servers?
Add your server