Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for environment variables files?

I was just wondering if there was any standardized convention for .env environment variable files. If I had multiple setups (e.g. development, staging, production), what should they be titled?

I've seen:

  • .env.development, ...
  • development.env, ...
  • settings.development.env, ...
  • .env, .env.staging, .env.production, ...

If there isn't a standard, are there arguments for which to use (kinda like "" vs '' for strings in JS)? Which do you use and why?

like image 341
Leander Rodrigues Avatar asked Apr 01 '19 15:04

Leander Rodrigues


People also ask

How do you name environment variables?

Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit.

What format does the env var and its values are stored?

In Microsoft Windows, each environment variable's default value is stored in the Windows Registry or set in the AUTOEXEC. BAT file.

What are .env files?

What is a . env file? A . env file or dotenv file is a simple text configuration file for controlling your Applications environment constants. Between Local, Staging and Production environments, the majority of your Application will not change.


2 Answers

There is only one standard in node ecosystem - use production in NODE_ENV variable for production. It's used by different tools for optimizing.

The rest is on you. But personally, I don't see reasons to make it complex. If you need to differentiate instances further than just production, development, you can use other environment variables.

Also you need to be careful when using different NODE_ENV for staging and production. Because the main purpose of staging is to test everything as close to production as possible. So changing NODE_ENV can be a reason to production fail.

like image 159
iofjuupasli Avatar answered Oct 25 '22 02:10

iofjuupasli


I'm using this convention since I can't find any other suggestions: https://rubyonjets.com/docs/env-files/

.env
.env.development
.env.test
.env.production

I like maintaining the .env at the front and this seems reasonable to me.

like image 37
Bix Avatar answered Oct 25 '22 03:10

Bix