Support for .env files
See original GitHub issueRight now to use a .env file I need to install the dotenv package and import it and run it inside the entry.server file, which is a simple thing to do but it would be nicer to have it already built-in by Remix (only server-side of course).
So if a project has a .env file it can use it automatically.
This should probably be added to the adapters, if using Vercel it already loads the .env (because vercel dev does it), for Express it could be added here https://github.com/remix-run/remix/blob/master/packages/remix-express/server.ts or in the Remix Serve package instead https://github.com/remix-run/remix/blob/master/packages/remix-serve/index.ts (which may be a better place).
Some extra step that may or may not be useful here could be to support .env, .env.development, .env.production and .env.local with this behavior:
- First load from
.env, these are env shared everywhere - Then load from
.env.developmentor.env.productionbased on the NODE_ENV value (maybe also.env.test), these are env specific (as the.envshould be) - Then load from
.env.localand these let you overwrite the previous one, useful to trying things
Each one should overwrite the previous one.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Also a callout, I tend to not use dotenv in code, this couples ENV loading to your application. You can instead use the
dotenv-cliin-front of whatever startup command you use:If you ever do this, don’t be like Next and don’t overwrite system env variables