0.18.4 • Published 13 days ago

effect-dotenv v0.18.4

Weekly downloads
-
License
MIT
Repository
github
Last release
13 days ago

effect-dotenv

dotenv ConfigProvider implementation for Effect-TS

pnpm add effect-dotenv

Using setConfigProvider layer

setDotEnvConfigProvider creates a layer that will attempt to load the .env file. If the .env file doesn't exist, it will use the current ConfigProvider instead. If a .env is found, the derived ConfigProvider will be used as a fallback of the current ConfigProvider. This results in the standard behaviour where environment variable is used if set, otherwise it attempts to load it from the .env file.

The input parameters can be

  • ommited completely - .env file is used by default
  • a string - it will attempt to load a file on the given path
  • list of strings - it will use the first existing .env file from the list
import { NodeContext } from "@effect/platform-node"
import { Config, Effect, pipe } from "effect";
import { DotEnv } from "effect-dotenv";

const exampleConfig = Config.all({
  value: Config.string("VALUE"),
});

const program = pipe(
  Effect.config(exampleConfig),
  Effect.flatMap((config) => Effect.log(`value = ${config.value}`)),
  Effect.provide(DotEnv.setConfigProvider()),
  Effect.provide(NodeContext.layer)
);

Effect.runPromise(program);

Using makeConfigProvider effect

The example below configures config provider that will read the config from .env file. The program effect will fail with NoAvailableDotEnvFileError error if the .env file doesn't exist.

import { NodeContext } from "@effect/platform-node"
import { Config, Effect, Layer, pipe } from "effect";
import { DotEnv } from "effect-dotenv";

const exampleConfig = Config.all({
  value: Config.string("VALUE"),
});

const program = pipe(
  Effect.config(exampleConfig),
  Effect.flatMap((config) => Effect.log(`value = ${config.value}`)),
  Effect.provide(
    pipe(
      DotEnv.makeConfigProvider(".env"),
      Effect.map(Layer.setConfigProvider),
      Layer.unwrapEffect,
    ),
  ),
  Effect.provide(NodeContext.layer)
);

Effect.runPromise(program);
0.18.4

13 days ago

0.18.2

21 days ago

0.18.3

20 days ago

0.18.1

1 month ago

0.18.0

1 month ago

0.17.19

1 month ago

0.17.20

1 month ago

0.17.18

1 month ago

0.17.17

2 months ago

0.17.16

2 months ago

0.17.15

2 months ago

0.17.14

2 months ago

0.17.13

2 months ago

0.17.12

2 months ago

0.17.11

2 months ago

0.17.10

2 months ago

0.17.6

2 months ago

0.17.7

2 months ago

0.17.8

2 months ago

0.17.9

2 months ago

0.17.5

2 months ago

0.17.4

3 months ago

0.17.3

3 months ago

0.17.2

3 months ago

0.17.1

3 months ago

0.17.0

3 months ago

0.16.3

4 months ago

0.16.2

4 months ago

0.16.1

5 months ago

0.16.0

5 months ago

0.15.2

5 months ago

0.15.1

5 months ago

0.15.0

5 months ago

0.14.2

6 months ago

0.11.0

7 months ago

0.12.0

7 months ago

0.13.0

7 months ago

0.14.0

6 months ago

0.13.1

7 months ago

0.14.1

6 months ago

0.13.2

7 months ago

0.13.3

6 months ago

0.13.4

6 months ago

0.9.4

8 months ago

0.9.3

8 months ago

0.9.6

8 months ago

0.9.5

8 months ago

0.10.0

7 months ago

0.9.0

8 months ago

0.8.0

8 months ago

0.9.2

8 months ago

0.9.1

8 months ago

0.5.0

9 months ago

0.7.0

8 months ago

0.6.1

8 months ago

0.6.0

8 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.0

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago