npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rduk/configuration

v2.2.3

Published

Manage configuration in your Node.js app

Downloads

15

Readme

RDUK - configuration

Manage your Node.js app configuration

Build Status Coverage Status bitHound Overall Score

Installation

npm install @rduk/configuration --save --save-exact

Naming

Add the configuration file at the root of your project. You have to name it according to the argument passed to the factory.

var configuration = require('@rduk/configuration');

var myConfig;

/* config.yml */
myConfig = configuration();

/* config.dev.yml */
myConfig = configuration('dev');

/* config.prod.yml */
myConfig = configuration('prod');

Note:

If you set NODE_ENV, you can access the configuration according to it

myConfig = configuration.load(); //will load config.dev.yml if NODE_ENV === dev

Note:

If you prefer put your config file within another folder, you can do so by adding in the package.json of your solution a rduk configuration section.

# example of package.json (path/to/config/app.yaml)
{
    ...
    "rduk": {
        "config": {
            "path": "path/to/config", # (default: PWD)
            "ext": ".yaml", # (default: .yml)
            "prefix": "app" # (default: config)
        }
    }
}

or use RDUK_CONFIG_* environment variables as follow :

  • RDUK_CONFIG_PATH=path/to/config
  • RDUK_CONFIG_EXT=.yaml
  • RDUK_CONFIG_PREFIX=app

Reference

Configuration

Configuration.settings

Get the SettingsSection of the config file

yaml:

settings:
    facebook:
        appId: APP_ID
        appSecret: APP_SECRET

usage:

var fbSettings = myConfig.settings.get('facebook');

console.log(fbSettings.appId); //will output APP_ID
console.log(fbSettings.appSecret); //will output APP_SECRET

Configuration.connections

Get the ConnectionsSection of the config file

yaml:

connections:
    -
        name: con1
        host: localhost
        user: db1_user
        password: 123456
        database: db1
    -
        name: con2
        host: localhost
        user: db2_user
        password: 123456
        database: db2
    -
        name: mapbox
        token: my_mapbox_token
    -
        name: gmap
        token: my_gmap_token

usage:

var con1 = myConfig.connections.get('con1');
var con2 = myConfig.connections.get('con2');

console.log(myConfig.connections.get() === myConfig.connections.get('con1')); //will output true

Configuration.getSection(name, type)

Get the specified section

yaml:

map
    default: mapbox
    providers:
        -
            name: mapbox
            type: MapBoxProvider
            connection: mapbox
        -
            name: gmap
            type: GoogleMapProvider
            connection: gmap

section:

var MapSection = function(section) {
    /* ... */
};

usage:

var map = myConfig.getSection('map', MapSection);

Note:

If no type passed to the method, get the raw section.


License and copyright

See LICENSE