All Projects → pietvanzoen → Deno Dotenv

pietvanzoen / Deno Dotenv

Licence: mit
Dotenv file handling for deno.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Deno Dotenv

Dotenv Kotlin
🗝️ Dotenv is a module that loads environment variables from a .env file
Stars: ✭ 326 (+236.08%)
Mutual labels:  dotenv
Dotenv Linter
⚡️Lightning-fast linter for .env files. Written in Rust 🦀
Stars: ✭ 802 (+726.8%)
Mutual labels:  dotenv
Reenv
dotenv-cli implementation in native ReasonML providing near-instant startup times
Stars: ✭ 65 (-32.99%)
Mutual labels:  dotenv
Sync Dotenv
Keep your .env in sync with .env.example
Stars: ✭ 393 (+305.15%)
Mutual labels:  dotenv
Django Dotenv
Loads environment variables from .env
Stars: ✭ 481 (+395.88%)
Mutual labels:  dotenv
Authorize Slim 4
Slim 4 Authorization Tutorial
Stars: ✭ 39 (-59.79%)
Mutual labels:  dotenv
php-dotenv
Parses .env files
Stars: ✭ 48 (-50.52%)
Mutual labels:  dotenv
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-9.28%)
Mutual labels:  dotenv
Dotenv Flow
Loads environment variables from .env.[development|test|production][.local] files for Node.js® projects.
Stars: ✭ 537 (+453.61%)
Mutual labels:  dotenv
Building A Serverless Rest Api With Nodejs
A quick and easy guide of how to hook up a single Serverless service with basic MongoDB connection and CRUD interaction.
Stars: ✭ 57 (-41.24%)
Mutual labels:  dotenv
Pgsh
Branch your PostgreSQL Database like Git
Stars: ✭ 428 (+341.24%)
Mutual labels:  dotenv
Nestjs Config
Config module for nestjs using dotenv 🔑
Stars: ✭ 474 (+388.66%)
Mutual labels:  dotenv
Dotenv Webpack
A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
Stars: ✭ 1,022 (+953.61%)
Mutual labels:  dotenv
Python Dotenv
Get and set values in your .env file in local and production servers. 🎉
Stars: ✭ 4,533 (+4573.2%)
Mutual labels:  dotenv
Dotenv Java
🗝️ Dotenv is a no-dep, pure Java module that loads environment variables from a .env file
Stars: ✭ 72 (-25.77%)
Mutual labels:  dotenv
Dotenv
Symfony Dotenv parses .env files to make environment variables stored in them accessible via getenv(), $_ENV, or $_SERVER.
Stars: ✭ 3,268 (+3269.07%)
Mutual labels:  dotenv
React Native Dotenv
A Babel preset let you import application configs from .env file (zero runtime dependency)
Stars: ✭ 895 (+822.68%)
Mutual labels:  dotenv
Next Starter
Next.js Starter using GraphQL, MobX (Next.js, TypeScript, Babel, Express.js, Apollo Client, React Apollo, React Apollo Hooks, GraphQL Codegen, MobX, mobx-state-tree, styled-components, next-optimized-images, Serverless Framework, AWS Lambda, Dotenv)
Stars: ✭ 90 (-7.22%)
Mutual labels:  dotenv
Cr Dotenv
Loads ".env" files
Stars: ✭ 80 (-17.53%)
Mutual labels:  dotenv
Serverless Export Env
Serverless plugin to export environment variables into a .env file
Stars: ✭ 51 (-47.42%)
Mutual labels:  dotenv

Dotenv Build Status GitHub tag (latest SemVer)

Dotenv handling for deno.

Usage

Setup a .env file in the root of your project.

# .env
GREETING=hello world

Then import the configuration using the config function.

// app.ts
import { config } from "https://deno.land/x/dotenv/mod.ts";

console.log(config());

Then run your app.

> deno app.ts
{ GREETING: "hello world" }

Options

  • path?: string: Optional path to .env file. Defaults to ./.env.
  • export?: boolean: Set to true to export all .env variables to the current processes environment. Variables are then accessable via Deno.env.get(<key>). Defaults to false.
  • safe?: boolean: Set to true to ensure that all necessary environment variables are defined after reading from .env. It will read .env.example to get the list of needed variables.
  • example?: string: Optional path to .env.example file. Defaults to ./.env.example.
  • allowEmptyValues?: boolean: Set to true to allow required env variables to be empty. Otherwise it will throw an error if any variable is empty. Defaults to false.
  • defaults?: string: Optional path to .env.defaults file which defaults to ./.env.defaults.

Auto loading

load.ts automatically loads the local .env file on import and exports it to the process environment:

# .env
GREETING=hello world
// app.ts
import "https://deno.land/x/dotenv/load.ts";

console.log(Deno.env.get("GREETING"));
> deno --allow-env --allow-read app.ts
hello world

Safe Mode

To enable safe mode, create a .env.example file in the root of the project.

# .env.example
GREETING=

Then import the configuration with safe option set to true.

// app.ts
import { config } from "https://deno.land/x/dotenv/mod.ts";

console.log(config({ safe: true }));

If any of the defined variables is not in .env, an error will occur. This method is preferred because it prevents runtime errors in a production application due to improper configuration.

Another way to suply required variables is externally, like so:

GREETING="hello world" deno --allow-env app.ts

Default Values

Default values can be easily added via creating a .env.defaults file and using the same format as an.env file.

# .env.defaults
# Will not be set if GREETING is set in base .env file
GREETING="a secret to everybody"

Parsing Rules

The parsing engine currently supports the following rules:

  • BASIC=basic becomes {BASIC: 'basic'}
  • empty lines are skipped
  • lines beginning with # are treated as comments
  • empty values become empty strings (EMPTY= becomes {EMPTY: ''})
  • single and double quoted values are escaped (SINGLE_QUOTE='quoted' becomes {SINGLE_QUOTE: "quoted"})
  • new lines are expanded in double quoted values (MULTILINE="new\nline" becomes
{MULTILINE: 'new
line'}
  • Variables that already exist in the environment are not overridden with export: true
  • inner quotes are maintained (think JSON) (JSON={"foo": "bar"} becomes {JSON:"{\"foo\": \"bar\"}")
  • whitespace is removed from both ends of unquoted values (see more on trim) (FOO= some value becomes {FOO: 'some value'})
  • whitespace is preserved on both ends of quoted values (FOO=" some value " becomes {FOO: ' some value '})

Contributing

Issues and pull requests welcome. Please run make fmt before commiting.

Credit

  • Inspired by the node module dotenv.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].