Socket
Socket
Sign inDemoInstall

envari

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    envari

A safer way to load .env files


Version published
Weekly downloads
2
Maintainers
1
Install size
14.4 kB
Created
Weekly downloads
 

Readme

Source

Envari

A safer way to load .env files

Installation

npm i envari

or

yarn add envari

Options

  • properties: The properties that should be present in the .env file
  • missingPropertyBehavior: The action that should be taken if a required property is missing
    • "THROW" (default): Throw an error
    • "FALLBACK": Use an empty string for the property instead
  • filePath: The file path to the .env file (defaults to the .env file in the project root)

Usage

# .env
SECRET_KEY="******"
// env.js
import * as Envari from "envari";

export const env = Envari.load({
    properties: {
        SECRET_KEY: true,
    },
});

The result of calling Envari.load will be an object representation of your .env file. Envari also automatically populates process.env with your .env values.

// index.js
import { env } from "/env.js";

console.log(env.SECRET_KEY); // "******"
console.log(process.env.SECRET_KEY); // "******"

Example with all options used

import * as Envari from "envari";

const env = Envari.load({
    properties: {
        SECRET_KEY: true,
        SUPER_SECRET_KEY: true,
    },
    missingPropertyBehavior: "FALLBACK",
    filePath: "./some/path/to/.env",
});

console.log(env); // { SECRET_KEY: "******", SUPER_SECRET_KEY: "" }

License

MIT © Juan de Urtubey

Keywords

FAQs

Last updated on 07 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc