2.1.6 • Published 3 years ago

@diegopm2000/bk-configloader v2.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@diegopm2000/bk-configloader

npm (scoped) travis build Sonarcloud Status Bugs Vulnerabilities Technical DebtCode Smells Duplicated Lines (%) Coverage

BK (Bokarte) Config Loader

Utility to be used in your Node JS projects to allow loading configuration files from a local file in your system or loading configuration files from a remote endpoint. Specially recommended to use with a Spring Cloud Config service that serves the configuration stored in a GIT repository.

1. Install

npm install @diegopm2000/bk-configloader

You can install the package in your project package json too:

npm install @diegopm2000/bk-configloader --save

2. Usage

2.1 Loading config from file

Loading config from file. Only json or yaml file, both .yml and .yaml extensions are allowed.

Create in your local project path this file config.yml for testing and put in the same folder of your project. Recommended for development environments.

---
app:
  name: example App
  description: example App - configuration obtained from local yml file
  environment: development
log:
  level: debug
express:
  port: 8080

Example:

const configLoader = require('@diegopm2000/bk-configloader');

const options = {
  sourceType: configLoader.SOURCE_TYPE_FILE,
  filepath: './config.yml',
}

configLoader.load(options)
  .then((result) => {
    console.log(`result: ${JSON.stringify(result)}`);
  })
  .catch((error) => {
    console.error(error.stack});
  })

2.2 Loading config from remote endpoint

Loading config from remote endpoint.

You could use a spring cloud config based loader from GIT for example or another api rest for your convenience. Recommended for production environments, when you want that the application configuration will be decentralized.

const configLoader = require('bk-configloader');

const optionsRemote = {
  sourceType: configLoader.SOURCE_TYPE_REMOTE,
  filepath: 'config.json',
  remoteEndpoint: 'http://localhost:8888'
}

configLoader.load(options)
  .then((result) => {
    console.log(`result: ${JSON.stringify(result)}`);
  })
  .catch((error) => {
    console.error(error.stack});
  })
2.1.6

3 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

1.1.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago