DEV Community

Managing dotenv files in git repositories

Luke Harris on September 15, 2017

Sometimes your project needs access to sensitive information like an access token or database password. Maybe your project needs some configuration...
Collapse
 
bengreenberg profile image
Ben Greenberg

Thats a super helpful tool! I've created a couple projects that require a .env file and when someone's cloned it, I've had to walk them through what variables were required. This is much more streamlined and simpler. Thanks!

Collapse
 
karfau profile image
Christian Bewernitz • Edited

I don't get something here: we do not put .env under version control, to avoid leaking secrets, but then you put the data to put into the file into another file to generate it.

Why is this not defeating the purpose of not storing this data in version control?

Collapse
 
bdmason profile image
bdmason

It's instead of copying, renaming, and editing .env.example.

You don't put sensitive info in the json file, just defaults. When you run envup the interactive cli asks you to enter all the values.

I got that from the screenshot; it could be explained a little further in the article.

Collapse
 
gijovarghese profile image
Gijo Varghese

There is a much better way to set environment variables in NodeJS. I've written a detailed post - How I Setup Environment Variables in NodeJS. No, it’s not β€œdotenv”

Collapse
 
mgrachev profile image
Grachev Mikhail

In addition to using environment variables I can recommend the tool github.com/dotenv-linter/dotenv-li... β€” it’s a lightning-fast linter forΒ .env files. Written in Rust.
Maybe it would be useful for you.

Collapse
 
david_j_eddy profile image
David J Eddy

For the fellow PHP'ers out there, here is an amazing .env library. Add two lines to your applications init logic and you're off to the races. github.com/vlucas/phpdotenv

Collapse
 
_bigblind profile image
Frederik πŸ‘¨β€πŸ’»βž‘οΈπŸŒ Creemers

This looks cool! I'll use that in my next project. Can the env.json also be generated from an existing .env file?

Collapse
 
luk707 profile image
Luke Harris

Not currently but that could be very useful, I'll add an issue and get round to this at some point!

Collapse
 
gabedunn profile image
Gabe Dunn

Just added this to my project, works great!
Thanks :)