1.1.0 • Published 1 year ago

@ghii/envs-loader v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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=http://localhost
MYAPP_CONFIGS__0_URL__PORT=3000
MYAPP_CONFIGS__1_URL__PATH=/user
MYAPP_CONFIGS__1_URL__LOCAL=http://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: "http://localhost"
      port: "3000"
    - path: "/user"
      local: "http://myapp"
      port: "8080"

in JSON:

{
  "env": "development",
  "app": {
    "version": "0.0.1",
    "name": "ghii-test"
  }
  "configs": {
    "url": [
      {
        "path": "/test",
        "local": "http://localhost",
        "port": "3000"
      },
      {
        "path": "/user",
        "local": "http://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

1.1.0

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

3 years ago

1.0.0

3 years ago