1.0.5 • Published 2 years ago

use-config-json v1.0.5

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

use-config-json

Build Status NPM Package Version NPM Package Downloads Known Vulnerabilities GitHub Views GitHub Clones License: MIT

Load config.json without hassle

Install

$ npm i --save use-config-json

Usage

// CommonJS
const {loadConfig} = require('use-config-json');

/**
  JSON object, we will use this as a schema & fallback to default config value.

  Format: {
    [key: string]: "any"
  }

  const example = {
    "host": "127.0.0.1",
    "port": 3000
  }

  // This should be your default config file location to parse - if this value is undefined module will always try to load config.json
  const configFile = 'config.json'

  const config = loadConfig(example, 'config.json')
  console.log(config);
**/
const defaultConfig = {
  "host": "127.0.0.1",
  "port": 3000
}

const config = loadConfig(defaultConfig);
console.log(config);
// ES6 Modules
import loadConfig from 'use-config-json';

const defaultConfig = {
  "host": "127.0.0.1",
  "port": 3000
}

const config = loadConfig(defaultConfig);
console.log(config);
// TypeScript
import * as loadConfig from 'use-config-json';

const defaultConfig = {
  "host": "127.0.0.1",
  "port": 3000
}

const config: object = loadConfig(defaultConfig);
console.log(config);

Note

Note that nested objects wouldn't be parsed from process.env or either .env file as well

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago