Dotenv: Production server best practice documentation

Created on 27 Nov 2015  路  3Comments  路  Source: motdotla/dotenv

So I feel it's very clear how to use dotenv locally, but what's the alternatives when deploying?
Should we just skip using dotenv, or should we use it with a limited set of env values that are commitable?
How does dotenv solve our production/test-server env variable setup?

Any advices? I couldn't find any docs on it.

Most helpful comment

should we use it with a limited set of env values that are commitable?

I strongly suggest not committing any environment variables.

How does dotenv solve our production/test-server env variable setup?

It _really_ depends on your setup and because there are so many ways to do things, it's hard to document. There are two key questions to answer:

  1. What environment variables is my app expecting? (e.g. database name, database host, etc.)
  2. How will those variables be provided to my app in this environment? (e.g. locally I have a .env file)

If you're deploying to a server or VM like AWS EC2 or Digital Ocean, then you can put a .env file on that server where your app runs and it's exactly like running things locally.

If you use something like Heroku Dynos or AWS Elastic Beanstalk, environment variables are provided for you and should match what's in your local .env file. dotenv fails silently when the .env file is missing and everything should work as expected. (If you don't like the log line when the file is missing, use the silent configuration option.)

If you're deploying using a container system like Docker, you can use their configuration arguments or Compose to set environment variables.

Hope this helps!

All 3 comments

should we use it with a limited set of env values that are commitable?

I strongly suggest not committing any environment variables.

How does dotenv solve our production/test-server env variable setup?

It _really_ depends on your setup and because there are so many ways to do things, it's hard to document. There are two key questions to answer:

  1. What environment variables is my app expecting? (e.g. database name, database host, etc.)
  2. How will those variables be provided to my app in this environment? (e.g. locally I have a .env file)

If you're deploying to a server or VM like AWS EC2 or Digital Ocean, then you can put a .env file on that server where your app runs and it's exactly like running things locally.

If you use something like Heroku Dynos or AWS Elastic Beanstalk, environment variables are provided for you and should match what's in your local .env file. dotenv fails silently when the .env file is missing and everything should work as expected. (If you don't like the log line when the file is missing, use the silent configuration option.)

If you're deploying using a container system like Docker, you can use their configuration arguments or Compose to set environment variables.

Hope this helps!

If you use something like Heroku Dynos or AWS Elastic Beanstalk, environment variables are provided for you and should match what's in your local .env file. dotenv fails silently when the .env file is missing and everything should work as expected. (If you don't like the log line when the file is missing, use the silent configuration option.)

This was the answer I needed, so thank you!

save my day 馃憤

Was this page helpful?
0 / 5 - 0 ratings