Socket
Socket
Sign inDemoInstall

feathers-configuration

Package Overview
Dependencies
5
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    feathers-configuration

A small configuration module for your Feathers application.


Version published
Maintainers
3
Install size
309 kB
Created

Changelog

Source

v0.4.2 (2017-10-15)

Full Changelog

Closed issues:

  • Missing TypeScript declaration file #48
  • Feathers writing in typescript fails to boot on configuration #47
  • Prevent automatic expansion of environment variables #42
  • Getting Env name #41
  • Nested configuration #38
  • Stuck in configuration loophole... #37
  • Docs are wrong #36
  • Why use "NODE_ENV=development" with default.json? #33

Merged pull requests:

Readme

Source

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.

Keywords

FAQs

Last updated on 15 Oct 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc