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.

Define custom .env files for custom development stages.

See original GitHub issue

I think it would be useful to be able to define a custom .env file.

I have three different environments my app will run on: dev, staging, and production. dev and production are covered, but right now it doesn’t seem like there’s any easy way to have separate environment variables for other stages.

It would be handy if an additional environment variable could be specified to select the custom .env file, and use the default .env files if the additional variable is undefined.

e.g. (in Windows)

start: react-scripts start - uses .env.development start: "set REACT_APP_ENV=devstaging & react-scripts start" - uses .env.devstaging build_staging: "set REACT_APP_ENV=staging & react-scripts build" - uses .env.staging build: "react-scripts build" - uses .env.production

The custom .env file would be overriden by the .local version, just how it works currently with development, production, and test.

I’m not confident enough to make the change myself, but it seems like adding this would require a change in the react-scripts -> config -> jest -> env.js file, where the dotenvFiles variable is set (react-scripts v1.0.11).

Creating this from my comment on Issue 102 A way to define custom environment variables.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

39reactions
iansucommented, Feb 12, 2018

It looks like there’s an existing package called env-cmd that solves this issue: https://github.com/toddbluhm/env-cmd

Using this package you could create an env file for your environment (like .env.staging) and then run env-cmd .env.staging react-scripts start.

The settings in .env.staging will override the settings in .env.development.

7reactions
iansucommented, Jan 23, 2018

This seems like a reasonable proposal to me. I’d be happy to implement this if it’s something we want to go ahead with.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to customize Node.js .env files for different environment ...
By default, custom-env picks the .env file for your dev stage. However, to customize for a different stage, add the name as a...
Read more >
Customizing Node.js .env files - LogRocket Blog
Learn how to configure a Node.js application via environment variables and customize an .env file with new environment variables.
Read more >
Managing .env variables for provisional builds with Create ...
Thankfully, dotenv comes out of box. Let's create .env files under the root folder to manage environment variables. The files are .env ,...
Read more >
Using multiple .env files. - Prisma
One solution is to have multiple .env files which each represent different environments. In practice this means you create a file for each...
Read more >
React environment variables: A developer's guide - Architect.io
env files for each of these environments. The main .env file usually contains all common/shared environment variables while other .env files ...
Read more >

github_iconTop Related Medium Post

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 Hashnode Post

No results found