0.0.5 • Published 12 months ago

make-node-env v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

npm version

NPM

NPM

NPM

make-node-env

Make use of json file formatting for handling node environment configs.

Installation

Using npm:

npm i make-node-env

or

Using yarn:

yarn add make-node-env

Setup

/**
 * Using Sync configuration loading
 */
const syncConfg = path.resolve(__dirname + `/config2.json`);
exports.syncConfig = SyncConfig({ path: syncConfg, debug: true });

/**
 * Using Async configuration loading
 */
const asyncConfg = path.resolve(__dirname + `/config.json`);
exports.asyncConfig = async function () {
    return await AsyncConfig({ path: asyncConfg, debug: true })
};

Usage sample with Jest test

const { syncConfig, asyncConfig } = require('./index.js');

test('Configuration using sync load with config2.json', function () {
  const host = syncConfig.get('api.host');
  expect(host).toMatchObject({
    "url": "https://www.sync.com",
    "port": 9000,
    "hasSSL": true
  })

  const value = syncConfig.get('api.host.hasSSL');
  expect(value).toBe(true);
});

test('Configuration using async load with config.json', function () {
  async function load() {
    const config = await asyncConfig();

    const host = config.get('webURLs.api.host');
    expect(host).toMatchObject({
      "url": "https://www.host.com",
      "port": 9000,
      "hasSSL": true
    })

    const value = config.get('webURLs.api.host.hasSSL');
    expect(value).toBe(true);
  }

  load();
});

Jest Test

0.0.3

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.2

1 year ago

0.0.1

1 year ago