Socket
Socket
Sign inDemoInstall

dotenv-json-complex

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-json-complex


Version published
Weekly downloads
518
decreased by-59.75%
Maintainers
1
Install size
5.05 kB
Created
Weekly downloads
 

Readme

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

FAQs

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc