penv
.env loader for Dart

Basic Usage

Part of the Examples. Load a .env file and read a few keys, including the typed accessors.

Source: example/penv_example.dart

// Run this example from the package root:
//   dart run example/penv_example.dart
//
// On first run there's no `.env` file yet, so penvload will create a
// placeholder at .env and throw EnvFileNotFoundException. Fill in the
// generated file and run again to see it load successfully.

// print() is fine in example scripts; avoid it in production code instead.
// ignore_for_file: avoid_print

import 'package:penv/penv.dart';

void main() {
  try {
    final env = penvload('.env');

    print('Loaded ${env.length} variable(s):');
    env.forEach((key, value) => print('  $key=$value'));
  } on EnvFileNotFoundException catch (e) {
    print(e);
  }
}

Run it from the package root:

dart run example/penv_example.dart