@yandex-lms-ext/config

1.0.3 • Public • Published

@yandex-lms-ext/config

npm

NodeJS application configuration library. It loads your configs as NodeJS modules, not JSONs.

Quick Start

Install package:

npm install @yandex-lms-ext/config

Create config directory:

project/
  config/
    default.js
    local.js
    development.js
    testing.js
    production.js

Import library and use resulting config object:

import { config } from '@yandex-lms-ext/config';

console.log(config);

Define NODE_ENV and run script:

NODE_ENV=development node index.js

config object will include settings from config/default.js, config/development.js and config/local.js. If there is a conflict of keys, the objects will be expanded, arrays and primitives will be overridden.

Example

default.js

const config = {
  logger: {
    level: 'info'
  },

  server: {
    port: 80,
    ips: ['127.0.0.1']
  }
};

module.exports = config;

development.js

const config = {
  backend: {
    baseUrl: 'https://dev-api.weather.yandex.ru/v1/'
  },

  static: {
    baseUrl: '/static'
  }
};

module.exports = config;

local.js

const config = {
  backend: {
    baseUrl: 'http://127.0.0.1:8090/v1/'
  },

  server: {
    port: 8080,
    ips: ['127.0.0.1', '192.168.1.69']
  }
};

module.exports = config;

Resulting object:

const config = {
  backend: {
    baseUrl: 'http://127.0.0.1:8090/v1/'
  },

  logger: {
    level: 'info'
  },

  server: {
    port: 8080,
    ips: ['127.0.0.1', '192.168.1.69']
  },

  static: {
    baseUrl: '/static'
  }
};

TypeScript integration

You can use this module in TypeScript projects without pain. See example directory.

VSCode autocomplete

One caveat: you will have to describe your configuration manually.

Readme

Keywords

Package Sidebar

Install

npm i @yandex-lms-ext/config

Weekly Downloads

0

Version

1.0.3

License

MPL-2.0

Unpacked Size

19.8 kB

Total Files

4

Last publish

Collaborators

  • evgenymarkov
  • semyonmakhaev