jsonprocenv

1.0.1 • Public • Published

jsonprocenv

Sets your JSON env file to the process environment automatically.

The package flattens the JSON objects and provide easy and cleaner way to define your own process env variables, without the long and complex traditional .env file.

NPM Version

Simple usage

require("jsonprocenv")();  // Default ENV file path equals to "./.env".

Installation

npm install jsonprocenv --save

Usage examples

Whereas "myenvfile.json" contains the following JSON:

{
    "db": {
        "host": "mongodb://mymongoserver.example.com:27017",
        "collections": {
          "users": "usersCollection"
        }
    },
    "apiKeys": {
        "api1": "1as23f4sdf96sd4f32d14f7g8dfd45dfg3df4f",
        "api2": "798wer7t89e9g7df564dfg2df1g6dfg7df65g6"
    }
}

Setting the data to process.env:

require("jsonprocenv")("./myenvfile.json");

console.log(process.env.DB_HOST) // Will print out: "mongodb://mymongoserver.example.com:27017"
console.log(process.env.DB_COLLECTIONS_USERS) // Will print out: "usersCollection"
console.log(process.env.APIKEYS_API1) // Will print out: "1as23f4sdf96sd4f32d14f7g8dfd45dfg3df4f"

Readme

Keywords

none

Package Sidebar

Install

npm i jsonprocenv

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

2.67 kB

Total Files

3

Last publish

Collaborators

  • galmeiri