Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

configly

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configly

Provides an easy way to set up environmental configuration

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
482
increased by30.27%
Maintainers
1
Weekly downloads
 
Created
Source

configly

NPM version NPM dependencies Build Status

A simple configuration management module used for node projects.

Installation

$ npm install configly --save

Usage

var config = require('configly');

Create a directory in the root of your project called config.

Every .js and .json in that directory will be included in the config object returned.

For example: if you create a file called lib.json with these contents...

{
  "foo": "bar"
}

...the final config object will look like this...

{
  lib: {
    foo: 'bar'
  }
}

If you use a .js file instead of a .json file, then you just need to make sure you put stuff in the module.exports object. The above example in .js form...

module.exports = {
  lib: {
    foo: 'bar
  }
};

If you have a multi-word filename, only use dashes and underscores to separate the words. This is because the filename is converted to camelCase.

For example: if you create a file called user-permissions.json with these content...

{
  "/": [
    "anonymous",
    "admin"
  ],
  "/admin": [
    "admin"
  ]
}

...the final config object will look like this...

{
  userPermissions: {
    '/': [
      'anonymous',
      'admin'
    ],
    '/admin': [
      'admin'
    ]
  }
}

Environment

To signify that a config file is an environment config file, use this naming convention:

env.[environment name].js(on)

The environment name should be the name of the environment you want the config file to be for.

For example, if it's for a development environment, you should name the config file env.development.json or env.development.js.

To change the environment used, you just need to specify the NODE_ENV variable when running your app. E.g. NODE_ENV=production node app

If no NODE_ENV variable is provided, it will default to development, so you should always have an env.development.json file

Caveats

Although you can a config file with the same name but have different extentions (i.e. .js and .json), you shouldn't because one of them will not be included. From the tests that I've done, it takes the .json version because it shows up later in the list. At any rate, it seems like it would be bad practice to have two files with the same name in the same directory.

Your config directory has to be where your process.cwd() resides. In the future, I would like this to be configurable, but in the spirit of quick iterations and getting feedback, I will save that for another day.

Keywords

FAQs

Package last updated on 28 Jan 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc