dotenv 0.1.1

dotenv #

Load environment variables at runtime from a .env file.

Pub Version Build Status

NB: Travis uses test_runner, which has not yet moved off unittest.

usage #

Prefix the library import and call load(), exposing the env map with a top-level getter.

import 'package:dotenv/dotenv.dart' as dotenv;

Map<String, String> get _env => dotenv.env;

void main() {
  var x = _env['foo'];
  // ...

Verify required variables are present:

const _requiredEnvVars = const ['host', 'port'];

bool get hasEnv => dotenv.isEveryDefined(_requiredEnvVars);

limitations #

Variable substitution and character escaping is a work in progress. Some cases don't work yet. Pull requests gleefully considered.

prior art #

changelog #

This project follows pub-flavored semantic versioning.

Release notes are available on github.

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.


import 'package:dotenv/dotenv.dart' as dotenv;
import 'package:logging/logging.dart';

get env => dotenv.env;

final log = new Logger('example');

void main() {

  dotenv.load();'main: value of foo is ${env['foo']}');'main: value of baz is ${env['baz']}');

void _config() {
  Logger.root.level = Level.FINE;
  Logger.root.onRecord.listen((LogRecord rec) {
    print('${} ${_toMsg(rec)}');

String _toMsg(LogRecord rec) =>
    '${rec.time}: [${rec.loggerName}] ${rec.message}';

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dotenv: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support 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';
Awaiting analysis to complete.