Loads environment variables from .env for nodejs projects.

Overview

dotenv

Written in typescript, full testing.

It can loads environment variables from a .env file into process.env or parse <key>=<value> string

Installation

npm i @jsdotenv/core

Usage

Load env file

Add your application configuration to your .env file in the root of your project:

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE

Then in your Nodejs app you can do something like

import dotenv from "@jsdotenv/core";

dotenv.load([__dirname + "/.env"]);
console.log(process.env["S3_BUCKET"]);

If you want to be really fancy with your env file you can do comments and exports (below is a valid env file)

# I am a comment and that is OK
SOME_VAR=someval
FOO=BAR # comments at line end are OK too
export BAR=BAZ

Or finally you can do YAML(ish) style

FOO: bar
BAR: baz

Multiple line is OK.

MULTI_DOUBLE_QUOTED="THIS
IS
A
MULTILINE
STRING"

Expand variables is OK.

OPTION_B=${OPTION_A}
OPTION_C=$OPTION_B
OPTION_D=${OPTION_A}${OPTION_B}
OPTION_E=${OPTION_NOT_DEFINED}

Writing Env Files

dotenv can also write a map representing the environment to a correctly-formatted and escaped file.

const map = new Map();
map.set("BASIC", "basic");
map.set("KEY", "value");
const filepath = path.resolve(__dirname, "./jsfile/.env");
dotenv.write(map, filepath);

... or to a string

const map = new Map();
map.set("BASIC", "basic");
map.set("KEY", "value");
const lines = dotenv.marshal(map);

Exec commands

dotenv can run commands and inherit output.

exec bash commands

const pathname = path.resolve(__dirname + "/env/.env");
const out = dotenv.exec([pathname], "bash", ["-c", 'echo "$BASIC"']);

exec nodejs commands

const pathname = path.resolve(__dirname, "./jsfile/hello.js");
const out = dotenv.exec([], "node", [pathname]);

Cli

npm i create-dotenv -g

Usage

Execute commands using key-value pairs.

dotenv-cli -v KEY=VALUE -- bash -c 'echo "$KEY"'

Execute commands using enviroment file.

dotenv-cli -e .env -- bash -c 'echo "$BASIC"'

Execute commands --help for Usage

dotenv-cli --help
You might also like...

CLI utility that parses argv, loads your specified file, and passes the parsed argv into your file's exported function. Supports ESM/TypeScript/etc out of the box.

cleffa CLI tool that: Parses argv into an object (of command-line flags) and an array of positional arguments Loads a function from the specified file

Mar 6, 2022

Typescript package compatible with python's pickle loads/dumps

picklefriend Typescript package compatible with python's pickle loads/dumps Installation npm i picklefriend Usage import { pickle } from 'picklefriend

Oct 27, 2022

Experience Lab is a set of utilities that assist in creating instances of Microsoft Energy Data Services, performing data loads, and performing basic management operations.

Experience Lab - Microsoft Energy Data Services Build Status About Experience Lab is an automated, end-to-end deployment accelerator for Microsoft Ene

Dec 14, 2022

Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Parameter Store in bulk and output them in environment-file or json forma

Oct 18, 2022

Multiple `.env` file supported.

Features Support multiple .env files and keep the inheritance Priority: local not unassigned local mode not unassigned mode e.g. .env.{{mode}}.loc

Oct 31, 2022

Autocompletion, in-code secret peeking 🔎, syncing, and more, for your .env files in VSCode. 👑 From the same people who pioneered dotenv.

Autocompletion, in-code secret peeking 🔎, syncing, and more, for your .env files in VSCode. 👑 From the same people who pioneered dotenv.

Dotenv Official (with Vault) for VSCode Official Dotenv. Syntax highlighting, autocompletion, in-code secret peeking, and .env file syncing with Doten

Dec 19, 2022

Infisical — Sync your .env securely in seconds.

Infisical Infisical is a simple, end-to-end encrypted secrets manager for your .env files. It enables teams to securely sync and manage .env files in

Jan 4, 2023

Palette plugin using CSS variables for TailwindCSS

 Palette plugin using CSS variables for TailwindCSS

Palette plugin using CSS variables for TailwindCSS Adds a color palette (from 100 to 900) for each color of your tailwind configuration while using CS

Dec 28, 2022

An action intended to run on pull request and post a comment summarizing any changes to DevCycle variables.

An action intended to run on pull request and post a comment summarizing any changes to DevCycle variables.

Overview With this Github action, information on which DevCycle features have been added or removed in a code change will be shown directly on each Pu

Jun 14, 2022
Owner
Berlin
javascript lovers.
Berlin
Quo is a (free) debugging companion app to help you debug dumped variables, the dumped variables will appear in this Quo client instead of the traditional way which is often tedious.

Quo is a debugging companion to help you debug dumped variables, the dumped variables will appear in this Quo client instead of via the traditional way which is often tedious.

Protoqol 33 Dec 25, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A custom action for setting GitHub Workflow environment variables with YAML configuration files.

yaml-env-action - A custom action for setting GitHub Workflow environment variables with YAML configuration files. Introduction yaml-env-action is a c

Piper Dougherty 3 Dec 13, 2022
Displays environment variables on your Grafana dashboards

Displays environment variables on your Grafana dashboards Introduction The Environment data source is a plugin for Grafana that returns environment va

Volkov Labs 7 Dec 26, 2022
✨ A tool for versioning, securing and easily sharing environment variables

ev a tool for versioning, securing and easily sharing environment variables initializing • commands • using in your project Features ⏱ Version control

henrycunh 62 Dec 14, 2022
A package to enable feature-flag support on Next.js via cookies and environment variables

next-feature-flags Add support for feature flags on Next.js based on cookies + environment variables. How it works It reads from cookies and Next.js's

Alexandre Santos 10 Aug 10, 2022
mirrord lets you easily mirror traffic from your production environment to your development environment.

mirrord lets you easily mirror traffic from your Kubernetes cluster to your development environment. It comes as both Visual Studio Code extension and a CLI tool.

MetalBear 2.1k Dec 24, 2022
A multipurpose transporting app that contains, loads databases, documentation and more.

TransportingApp This project was generated with Angular CLI version 12.0.3. Development server Run ng serve for a dev server. Navigate to http://local

Sebastian Oliveros 1 Jan 21, 2022