Skip to content

iad-os/ghii-envs-loader

Repository files navigation

GHII - ENVS LOADER

envs loader is a ghii loader. it is used to load the configurations of a nodejs application by reading the right envs that are recognized thanks to the prefix.

How to install:

npm install @ghii/envs-loader

ENVS:

MYAPP_APP__VERSION=0.0.1
MYAPP_APP__NAME=ghii-test
MYAPP_CONFIGS__0_URL__PATH=/test
MYAPP_CONFIGS__0_URL__LOCAL=https://localhost
MYAPP_CONFIGS__0_URL__PORT=3000
MYAPP_CONFIGS__1_URL__PATH=/user
MYAPP_CONFIGS__1_URL__LOCAL=https://myapp
MYAPP_CONFIGS__1_URL__PORT=8080
MYAPP_ENV=development

Configuration in yaml:

env: development
app:
  version: "0.0.1"
  name: "ghii-test"
configs:
  url:
    - path: "/test"
      local: "https://localhost"
      port: "3000"
    - path: "/user"
      local: "https://myapp"
      port: "8080"

in JSON:

{
  "env": "development",
  "app": {
    "version": "0.0.1",
    "name": "ghii-test"
  }
  "configs": {
    "url": [
      {
        "path": "/test",
        "local": "https://localhost",
        "port": "3000"
      },
      {
        "path": "/user",
        "local": "https://myapp",
        "port": "8080"
      }
    ]
  }
}

Usage example:

import ghii from '@ghii/ghii';
import envsLoader from '@ghii/envs-loader';


const options = ghii((T) =>
  T.Object({
    env: T.Union([T.Literal("development"), T.Literal("production")], {
      default: "development",
    }),
    app: T.Object(
      {
        name: T.String({ default: "test" }),
        version: T.String(),
      },
      { additionalProperties: false, default: {} }
    ),
    configs: T.Object({
      url: T.Array(
        T.Object({ local: T.String(), path: T.String(), port: T.String() })
      ),
    }),
  })
).loader(envsLoader({ envs: process.env, prefix: 'MYAPP' }));
  //Load configurations via enviroment variables with the prefix MYAPP

Related

About

Ghii Config Environment Variable Loader

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published