dotenv 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

dotenv #

Load environment variables at runtime from a .env file.

Pub Version Build Status Documentation

about #

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, PATH, PORT, ...). 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 Platform.environment map.

usage #

See documentation and examples.

cli #

Get the latest:

$ pub global activate dotenv

Run:

$ 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

discussion

Use the issue tracker for bug reports and feature requests.

Pull requests gleefully considered.

prior art
license: MIT

changelog #

This project follows pub-flavored semantic versioning. (more)

Release notes are available on github.

2.0.0 #

  • BREAKING: change parser to handle = in values, e.g. base64 #21

1.0.0 #

  • Dart 2 compatible. #16

0.1.3+3

  • [docs] tweak README

0.1.3+2

  • [fix] don't throw if load fails #11

0.1.3+1

  • [fix] allow braces with ${var} substitution #10

0.1.3 #

  • [new] add command-line interface #7, #8
  • [deps] add args@v0.13

0.1.2 #

  • [new] support variable substitution from Platform.environment #6
  • [deps] drop logging

0.1.1+2

  • [fix] don't strip # inside quotes #5

0.1.1+1

  • [fix] whitespace causes quotes not to be stripped

0.1.1 #

  • [deprecated] Parser internals will become private. #3
    • #unquote, #strip, #swallow, #parseOne, #surroundingQuote, #interpolate
  • [new] support variable substitution
  • [deps] migrate to test
  • [deps] bump logging

0.1.0 #

Initial release.

example/example.dart

import 'dart:io';

import 'package:dotenv/dotenv.dart' show load, clean, isEveryDefined, env;

void main() {
  load();

  p('read all vars? ${isEveryDefined(['foo', 'baz'])}');

  p('value of foo is ${env['foo']}');
  p('value of baz is ${env['baz']}');
  p('your home directory is: ${env['HOME']}');

  clean();

  p('cleaned!');
  p('env has key foo? ${env.containsKey('foo')}');
  p('env has key baz? ${env.containsKey('baz')}');
  p('your home directory is still: ${env['HOME']}');
}

p(String msg) => stdout.writeln(msg);

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:

with pub:


$ pub get

with Flutter:


$ 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:


import 'package:dotenv/dotenv.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
86
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on May 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Health suggestions

Fix lib/src/parser.dart. (-2.48 points)

Analysis of lib/src/parser.dart reported 5 hints:

line 9 col 27: Unnecessary new keyword.

line 10 col 34: Unnecessary new keyword.

line 12 col 7: Unnecessary new keyword.

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.

Fix lib/dotenv.dart. (-1.99 points)

Analysis of lib/dotenv.dart reported 4 hints:

line 26 col 12: Unnecessary new keyword.

line 32 col 23: Unnecessary new keyword.

line 43 col 11: Unnecessary new keyword.

line 43 col 28: Unnecessary new keyword.

Fix bin/new.dart. (-1.49 points)

Analysis of bin/new.dart reported 3 hints:

line 7 col 17: Unnecessary new keyword.

line 42 col 11: Unnecessary new keyword.

line 42 col 28: Unnecessary new keyword.

Fix bin/dotenv.dart. (-0.50 points)

Analysis of bin/dotenv.dart reported 1 hint:

line 6 col 17: Unnecessary new keyword.

Maintenance suggestions

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
args ^1.0.0 1.6.0
dart2_constant ^1.0.0 1.0.2+dart2
meta ^1.0.2 1.1.8
Dev dependencies
collection any
test any