Load environment variables at runtime from a
Deploying applications should be simple. This implies constraints:
The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code... they are a language- and OS-agnostic standard.
An environment is the set of variables known to a process (say,
It is desirable to mimic the production environment during development (testing,
staging, ...) by reading these values from a file.
This library parses that file and merges its values with the built-in
Get the latest:
$ pub global activate dotenv
$ pub global run dotenv:new # create a .env file and add it to .gitignore $ pub global run dotenv # load the file and print the environment to stdout
Use the issue tracker for bug reports and feature requests.
Pull requests gleefully considered.
prior art #
- bkeepers/dotenv (ruby)
- motdotla/dotenv (node)
- theskumar/python-dotenv (python)
- joho/godotenv (go)
- slapresta/rust-dotenv (rust)
- chandu/dotenv (c#)
- tpope/lein-dotenv, rentpath/clj-dotenv (clojure)
- mefellows/sbt-dotenv (scala)
- greenspun/dotenv (half of common lisp)
Release notes are available on github.
- BREAKING: change parser to handle
=in values, e.g. base64 #21
- Dart 2 compatible. #16
- [docs] tweak README
- [fix] don't throw if load fails #11
- [fix] allow braces with
- [fix] don't strip
#inside quotes #5
- [fix] whitespace causes quotes not to be stripped
Parserinternals will become private. #3
- [new] support variable substitution
- [deps] migrate to test
- [deps] bump logging
Note consuming code must call
load before accessing the
From this directory, run
$ dart example.dart
Define variables in a
$ cp .env.example .env
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: dotenv: ^2.0.0
2. Install it
You can install packages from the command line:
$ pub get
$ flutter pub get
Alternatively, your editor might support
pub get or
flutter pub get.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.0
- pana: 0.12.21
Detected platforms: Flutter, other
lib/src/parser.dart. (-1 points)
lib/src/parser.dart reported 2 hints:
line 32 col 31: Use
= to separate a named parameter from its default value.
line 46 col 7: DO use curly braces for all flow control structures.
The package description is too short. (-14 points)
Add more detail to the
description field of
pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.