@nodearch/config

0.3.0 • Public • Published

NodeArch Config

Usage

config file example

server.json

[
  {
    "key": "host",
    "value": "http://localhost:3000",
    "type": "string",
    "env": "HOST",
    "required": true
  },
  {
    "key": "port",
    "value": 3000,
    "env": "PORT"
  }
]

main.ts

import { createInstance, IEnv, config } from '@nodearch/config';
import * as path from 'path' ;

async function main () {
  // config folder path
  const configPath = path.join(__dirname, '..', 'config');
  // environment to use
  const env = process.env.NODE_ENV || 'development';
  // environment data object i.e ( environment variables )
  const envVars: IEnv = <IEnv>process.env;
  // create config instance
  await createInstance(configPath, env, envVars);

  console.log("host", config.get("server.host") );
  console.log("port", config.get("server.port") );
}

main()
  .catch(err => {
    console.log(err.message);
    process.exit(1);
  });

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    0
    • latest

Version History

Package Sidebar

Install

npm i @nodearch/config

Weekly Downloads

0

Version

0.3.0

License

Apache-2.0

Unpacked Size

20.8 kB

Total Files

19

Last publish

Collaborators

  • ahmedali7o1