šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

dotenv-json-complex

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-json-complex

Load complex enviroment variable via JSON file

1.0.4
latest
Source
npm
Version published
Weekly downloads
926
41.16%
Maintainers
1
Weekly downloads
Ā 
Created
Source

dotenv-json-complex

Load complex enviroment variable via JSON file

Installation

With Nodejs installed run the installation command in a terminal:

npm install dotenv-json-complex

Usage

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

{
    "my_app_env": {
      "nodeEnv": "development",
      "api": {
        "prefix": "/api"
      },
      "database": {
        "username": "foo",
        "password": "bar",
        "name": "awesome_db_name",
        "host": "my_db_host"
      }
    }
}

After that, load your environment variables by requiring the dotenv dotenv-json-complex and executing it:

// here you load the json to your process.env
require("dotenv-json-complex")();

const env = JSON.parse(process.env.my_app_env);

// this will print your complex json environment!
console.log(env)

// like this
{
  "nodeEnv": "development",
  "api": {
    "prefix": "/api"
  },
  "database": {
    "username": "foo",
    "password": "bar",
    "name": "awesome_db_name",
    "host": "my_db_host"
  }
}

Furthermore you can provide an object to change environment filename:

require("dotenv-json-complex")({ environment: 'qa' });

This will look for .env.qa.json file and load it in memory.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Keywords

env

FAQs

Package last updated on 11 Jan 2021

Did you know?

Socket

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