New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

effect-dotenv

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effect-dotenv

dotenv effect wrapper

latest
Source
npmnpm
Version
0.24.1
Version published
Weekly downloads
22
-62.71%
Maintainers
1
Weekly downloads
 
Created
Source

effect-dotenv

dotenv + dotenv-expand as a ConfigProvider implementation for Effect-TS

Installation

pnpm add effect-dotenv

Usage

Use DotEnv.layer(<filename>) to replace the current ConfigProvider with a .env one.

import { Config, Effect } from "effect";
import { DotEnv } from "effect-dotenv";

import { NodeContext } from "@effect/platform-node";

const program = Effect.gen(function* () {
  const config = yield* Config.all({
    value: Config.string("VALUE"),
  });
  yield* Effect.log(`value = ${config.value}`);
}).pipe(
  Effect.provide(DotEnv.layer(".env")),
  Effect.provide(NodeContext.layer),
);

Effect.runPromise(program);

Alternatively, you can employ the DotEnv.layerAsFallback which sets a ConfigProvider that uses the .env as a fallback. It attemps to resolve the given config from the process.env (assuming the current config provider is the default one) and if not found it tries the .env.

In case you need a more customized setup, use the DotEnv.makeConfigProvider which produces an effect constructing the .env ConfigProvider. You'll probably want to use it along with the Layer.setConfigProvider combinator from effect.

FAQs

Package last updated on 07 Oct 2024

Related posts