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.

[feature] Implement dotenv-expand to accept variable expansion in dot env files

See original GitHub issue

Currently we use the dotenv library to parse a .env file in the project root and populate process.env. Great!

Although there exists scenarios in large scale deployments where the same environment variables are used accross many “app” or “services” or “containers”… For example

We have websites, API services and databases consuming a base set of environment variables such as:

  CDN
  STRIPE_KEY
  API_HOST
  VERSION_TAG

We don’t want to have to add another set to this simply with the leading key REACT_APP_XXX. Dotenv has a has a sister project / plugin called dotenv-expand that allows, wait for it… variable expansion in the file! e.g.

REACT_APP_CDN=${CDN}
REACT_APP_STRIPE_KEY=${STRIPE_KEY}
REACT_APP_API_HOST=${API_HOST}
REACT_APP_VERSION_TAG=${VERSION_TAG}

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
gaearoncommented, Jan 15, 2018

This is out in react-scripts@1.1.0! Please let us know if something doesn’t quite work. https://github.com/facebookincubator/create-react-app/releases/tag/v1.1.0

0reactions
mooscommented, Apr 13, 2018

FYI, to include an underscore in your expression use the ${ } format in your .env:

// bad
FOO_BAR=$npm_package_dependencies_foo_$npm_package_dependencies_bar
// 2.0

// good
FOO_BAR=${npm_package_dependencies_foo}_${npm_package_dependencies_bar}
// 1.0_2.0

where

// package.json
  "dependencies" : {
    "foo": "1.0",
    "bar": "2.0"
   }
Read more comments on GitHub >

github_iconTop Results From Across the Web

motdotla/dotenv-expand: Variable expansion for ... - GitHub
Dotenv -expand adds variable expansion on top of dotenv. If you find yourself needing to expand environment variables already existing on your machine, ......
Read more >
Master environment variables on Node.js with dotenv-expand
Dotenv -expand is an NPM library that adds variable expansion on top of the dotenv library we used before. It allows us to...
Read more >
Correct way to use dotenv-expand (.env) - Stack Overflow
Is it correct way to use dotenv-expand ? If so , it doens't work in my case . I want to create variable...
Read more >
Top 5 dotenv-expand Code Examples - Snyk
To help you get started, we've selected a few dotenv-expand examples, based on popular ways it is used in public projects. Secure your...
Read more >
Dotenv - Best of JS
Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env . Storing configuration in the environment separate ...
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