Giter VIP home page Giter VIP logo

dot2env's Introduction

dot2env | dotenv environment

This library allows the user to read different .env files based on the environment variable (NODE_ENV).

This project was inspired from dotenv.

Install

npm install dot2env

Usage

Simple

Create a .env file in the root of your project:

USERNAME="jex"
password="secret"

As early as possible in your application, import and configure dot2env:

import "@jexsrs/dot2env";

console.log(process.env.USERNAME);
console.log(process.env.PASSWORD);

Environments

The supported environments are:

  • production, prod
  • staging, stage
  • testing, test
  • development, dev

For each environment you will have to create a .env.[environment] file (using the full name).

Now everytime you call your application using an environment, it will automatically import all the variables in that file.

For example, running:

NODE_ENV=production node index.js

will import only the .env.production file.

If the .env.[environment] file is not found, it will always fallback to the .env file.

Override default variables

If you want to override existing environment variables, use the override option.

import {load} from "@jexsrs/dot2env";

load({override: true});

Custom mapping

In case you want to add more environments or use custom ones you can define your own mapping:

import {load} from "@jexsrs/dot2env";

load({
    envMap: {
        development: '.env.development',
        testing: '.env.testing',
        staging: '.env.staging',
        production: '.env.production',
        'custom-env': '.env.custom-environment'
    }
});

dot2env's People

Contributors

jexsrs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.