question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for .env files

See original GitHub issue

Right 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.development or .env.production based on the NODE_ENV value (maybe also .env.test), these are env specific (as the .env should be)
  • Then load from .env.local and these let you overwrite the previous one, useful to trying things

Each one should overwrite the previous one.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
jacob-ebeycommented, Aug 25, 2021

Also a callout, I tend to not use dotenv in code, this couples ENV loading to your application. You can instead use the dotenv-cli in-front of whatever startup command you use:

dotenv -- remix run
dotenv -- node server.js
4reactions
sergiodxacommented, Sep 10, 2021

If you ever do this, don’t be like Next and don’t overwrite system env variables

Read more comments on GitHub >

github_iconTop Results From Across the Web

env files support - IntelliJ IDEs Plugin - JetBrains Marketplace
Go to declaration(in .env file) and usages(in code), by Ctrl(Cmd)+click or hot key(Ctrl(Cmd)-B, etc.) ...
Read more >
We need to talk about the .env | Platform.sh
.env files are a surrogate environment variable for local development only, but should never be committed to Git. Understand your application!
Read more >
Managing .env files and setting variables - Prisma
Learn how to manage .env files and set environment variables.
Read more >
Support for dotenv (`.env`) files · Issue #461 · google/zx - GitHub
we may need these .env files in any folder; we do not want to add package.json and install additional packages; fetching data from...
Read more >
Env File (2022): The Only Guide You'll Need - Onboardbase
To avoid hardcoding constants - Using .env files is a common web server security best practice, as they prevent you from directly writing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found