Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

feathers-configuration

feathersjs1.8kMITdeprecated0.4.2TypeScript support: included

Feathers v3 is out and this module has moved to @feathersjs/configuration. See https://docs.feathersjs.com/migrating.html for more information.

A small configuration module for your Feathers application.

feathers, feathers-plugin

readme

feathers-configuration

Greenkeeper badge

Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

A small configuration module for your Feathers application.

About

The v0.4.x release of feathers-configuration is a breaking version and implementations that were made with earlier versions of the module may be required to make some minor changes. Please see the migrating section for specifics.

This module is a simple wrapper on node-config that adds a bit of convenience. By default this implementation will look in config/* for default.json which retains convention. As per the config docs you can organize "hierarchical configurations for your app deployments". See the usage section below for better information how to implement this.

Please note: future releases will also include the ability to define adapters which will allow you to use external configuration storage like vault or etcd.

Migrating

Moving from 0.3.x to 0.4.x should be mostly backwards compatible. The main change is that instead of passing the location of your configuration into the module constructor like this:

let config = require('feathers-configuration')(root, env, deepAssign);

The module now simply inherits from NODE_ENV and NODE_CONFIG_DIR as per the node-config docs:

$ NODE_ENV=development NODE_CONFIG_DIR=./config/ node app.js 

If you are currently setting your configurations via construction arguments, you will need to move these values out of your app into these environment variables.

With the implementation of node-config we also now have the ability to set a custom-environment-variables.json file which will allow you to define which variables to override from process.env. See below for examples.

Usage

The feathers-configuration module is an app configuration function that takes a root directory (usually something like __dirname in your application) and the configuration folder (set to config by default):

import feathers from 'feathers';
import configuration from 'feathers-configuration';

// Use the current folder as the root and look configuration up in `settings`
let app = feathers().configure(configuration())

Variable types

feathers-configuration uses the following variable mechanisms:

  • Given a root and configuration path load a default.json in that path
  • When the NODE_ENV is not development, also try to load <NODE_ENV>.json in that path and merge both configurations
  • Go through each configuration value and sets it on the application (via app.set(name, value)).
    • If the value is a valid environment variable (e.v. NODE_ENV), use its value instead
    • If the value starts with ./ or ../ turn it into an absolute path relative to the configuration file path
    • If the value is escaped (starting with a \) always use that value (e.g. \\NODE_ENV will become NODE_ENV)
  • Both default and <env> configurations can be modules which provide their computed settings with module.exports = {...} and a .js file suffix. See test/config/testing.js for an example.
    All rules listed above apply for .js modules.

Example

In config/default.json we want to use the local development environment and default MongoDB connection string:

{
  "frontend": "../public",
  "host": "localhost",
  "port": 3030,
  "mongodb": "mongodb://localhost:27017/myapp",
  "templates": "../templates"
}

In config/production.js we are going to use environment variables (e.g. set by Heroku) and use public/dist to load the frontend production build:

{
  "frontend": "./public/dist",
  "host": "myapp.com",
  "port": "PORT",
  "mongodb": "MONGOHQ_URL"
}

Now it can be used in our app.js like this:

import feathers from 'feathers';
import configuration from 'feathers-configuration';

let conf = configuration();

let app = feathers()
  .configure(conf);

console.log(app.get('frontend'));
console.log(app.get('host'));
console.log(app.get('port'));
console.log(app.get('mongodb'));
console.log(app.get('templates'));
console.log(conf());

If you now run

node app
// -> path/to/app/public
// -> localhost
// -> 3030
// -> mongodb://localhost:27017/myapp
// -> path/to/templates

Or via custom environment variables by setting them in config/custom-environment-variables.json:

{
  "port": "PORT",
  "mongodb": "MONGOHQ_URL"
}
$ PORT=8080 MONGOHQ_URL=mongodb://localhost:27017/production NODE_ENV=production node app
// -> path/to/app/public/dist
// -> myapp.com
// -> 8080
// -> mongodb://localhost:27017/production
// -> path/to/templates

You can also override these variables with arguments. Read more about how with node-config

License

Copyright (c) 2015

Licensed under the MIT license.

changelog

Change Log

v0.4.1 (2016-10-24)

Full Changelog

Closed issues:

  • Investigate node-config #8

Merged pull requests:

v0.4.0 (2016-10-22)

Full Changelog

Implemented enhancements:

Closed issues:

  • Deprecate v1 in favour of node-config #25
  • Make this repo more about managing configuration #24

v0.3.3 (2016-09-12)

Full Changelog

v0.3.2 (2016-09-12)

Full Changelog

Closed issues:

  • A way to have local override #20

Merged pull requests:

  • Remove check for development mode #21 (daffl)

v0.3.1 (2016-08-15)

Full Changelog

Merged pull requests:

v0.3.0 (2016-05-22)

Full Changelog

Closed issues:

  • <NODE_ENV>.json config need deep merge options #16

Merged pull requests:

  • Add functionality for deeply extending configuration #17 (daffl)

v0.2.3 (2016-04-24)

Full Changelog

Closed issues:

  • PR: Support modules in config #12

Merged pull requests:

v0.2.2 (2016-03-27)

Full Changelog

Merged pull requests:

v0.2.1 (2016-03-12)

Full Changelog

Merged pull requests:

  • Makes sure that arrays get converted properly #7 (daffl)

v0.2.0 (2016-03-09)

Full Changelog

Closed issues:

  • Needs an escape character #4

Merged pull requests:

  • Implement an escape character #6 (daffl)

v0.1.1 (2016-03-09)

Full Changelog

Closed issues:

  • Configuration should recursively go through the values #2

Merged pull requests:

  • Replace slashes in paths with the separator #5 (daffl)
  • Allow to convert deeply nested environment variables #3 (daffl)
  • Adding nsp check #1 (marshallswain)

v0.1.0 (2015-11-14)

* This Change Log was automatically generated by github_changelog_generator