19 Replies
Project ID:
N/A
Railway doesn't create
.env
files, they throw the service variables as environment variables into the docker container they create for your projectTo 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
i have added the variables in the dashboard already
Yes, railway won't create a
.env
file for those variablesthen how to access them in code?
in this case you need to removed the logic responsible for grabbing that file from your app
any way we can make railway to create .evn file?
you access env vars with
process.env.ENV_NAME
if it's node, I assume it isyes that's exactly how I am accessing them right now
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
@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
Yea you don't want it to load the .env file in production on railway
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
@maddsua Will have to eliminate config service then and use variables using dot env I believe
maybe there's an option to disable in case of certain variable already present?
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
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)