process.env is always undefined in production #87
-
I've just migrated a project to RRv7 and react-router-hono-server, my app is being deployed to Railway. The problem is that when I try to run it there I always get the process.env error: process.env.DATABASE_HOST undefined
Here's my server index:
Any ideas about how can I fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello 👋 I think you have to pass your environment variables before executing the start command or set them according to your hosting provider's recommendations. DATABASE_HOST=xxx npm run start Dotenv is only used in development mode. However, if you want to load an |
Beta Was this translation helpful? Give feedback.
Hello 👋
Is it happening on the production build?
According to the trace, I would say yes.
I think you have to pass your environment variables before executing the start command or set them according to your hosting provider's recommendations.
Dotenv is only used in development mode. However, if you want to load an
.env
file, add it to thebuild/server
folder, close to yourindex.js
becauseconfigDotenv
may expect to resolve the file relative to that location.