node-yaml-config
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

node-yaml-config

Build Status

Write your configuration files for node.js in yaml

Installation

npm install node-yaml-config

Usage

var yaml_config = require('node-yaml-config');

var config = yaml_config.load(__dirname + '/config/config.yml');

console.log(config); 

Or with Typescript:

import { loadAsync } from 'node-yaml-config';

async function main() {
  const config = await loadAsync(__dirname + '/config/config.yml');
  console.log(config);
}
main();

Configuration Files

In your configuration file:

default:
  server:
    port: 3000
  database:
    host: 'localhost'
    port: 27017
development:
  database:
    db: 'dev_db'
test:
  database:
    db: 'test_db'
production:
  server:
    port: 8000
  database:
    db: 'prod_db'
    user: 'dbuser'
    password: 'pass'
  cache:
    dir: 'static'

node-yaml-config takes the configuration found in default, then overwrites it with the values found in the environment specific parts. The configuration file is loaded synchronously.

API

read(filename)

Reads the configuration found in filename.

load(filename[, env])

Load the configuration found in filename with the environment based on NODE_ENV. The environment can be forced with the env argument.

node-yaml-config keeps parsed yaml files in memory to avoid reading files again.

reload(filename)

Reload the configuration found in filename. Later calls to load will show the new configuration.

The file is loaded synchronously.

readAsync(filename)

Same as read but returns a Promise.

loadAsync(filename[, env])

Same as load but returns a Promise.

node-yaml-config keeps parsed yaml files in memory to avoid reading files again.

reloadAsync(filename)

Same as reload but returns a Promise.

License

Copyright (c) 2012-2021 Johann-Michael Thiebaut <johann.thiebaut@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i node-yaml-config

Weekly Downloads

17,497

Version

1.0.0

License

MIT

Unpacked Size

38.5 kB

Total Files

15

Last publish

Collaborators

  • leafty