Socket
Book a DemoInstallSign in
Socket

configon

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configon

Configuration management for apps for multiple environments

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Configon

Gulp tool for generating configuration files for multiple environments on your app. Simply lets you generate templated files based on a specific environment config.

Table of Contents

  • Getting started
  • Usage
  • API
  • Contribute
  • License

Getting started

Install Configon

$ npm install configon --save-dev

Usage

You can simply add the following code on to your gulp file and start using it

var EnvConfig = require('configon');

const config = new EnvConfig( './example/config/config.@@ENV.json' )
            .addTemplate( './example/config/template.ts','./bin/config.ts' )
            .addTemplate( './example/config/template.xml','./bin/config.xml' );

gulp.task('config', function() {
    var defaultEnv = 'dev';
    config.build( defaultEnv );
});

Building your configuration for your environment

You can pass parameters with arguments through CLI or also set NODE_ENV environment variable or pass a parameter when you call build in your gulp task.

Following examples assumes that your gulp task is config

$ gulp config --env:< environment >

$ gulp config --env:dev

$ gulp config --env:prod

Using Environment variables

You can set environment variable with the identifier NODE_ENV

For just one run (from the unix shell prompt):

$ NODE_ENV=dev gulp config

More permanently:

$ export NODE_ENV=dev

$ gulp config

In Windows:

$ SET NODE_ENV=dev

Setting custom IP Address

This is useful if you are developing a mobile application and you want to point you app to a custom IP Address in your LAN

$ gulp config --ip:< IP Address >

$ gulp config --ip:192.168.0.100 --env:device

Setting up your templates and environment configuration values

This section tells you how to change configuration for environment

Configon uses gulp to change the configuration. It generates a file from a template file applying all configuration values from the configuration (value) files. It matches the key in template file with values in configuration file.

NOTE: Any text based files can be used as a template

Example template.ts

/**
 * Contains all Application configuration 
 */
export const AppConfig = {

    /**
     * Logging level
     */
    LOG_LEVEL : '@@LOG_LEVEL',
    
    /**
     * API URL of the server
     */
    API_URL : '@@API_URL'

}
 

config.json

{
    "LOG_LEVEL": "debug",
    "API_URL": "http://localhost:8080"
}

output.ts

/**
 * Contains all Application configuration 
 */
export const AppConfig = {

    /**
     * Logging level
     */
    LOG_LEVEL : 'debug',
    
    /**
     * API URL of the server
     */
    API_URL : 'http://localhost:8080'

}

Getting your Application name, version and build date into configuration.

You can add the following keys in your configuration file to automatically fetch the application name and version from package.json and build date from the system.

  • @@APP_NAME - Application Name
  • @@VERSION - Application version
  • @@BUILD_DATE - Application build date
  • @@ENV - Environment name

Example template.ts

    ...
    /**
     * Name of the app
     */
    APP_NAME : '@@APP_NAME',

    /**
     * Version of the app
     */
    VERSION : '@@VERSION',

    /**
     * Build date of the app
     */
    BUILD_DATE : '@@BUILD_DATE',
    
    /**
     * Build date of the app
     */
    ENV : '@@ENV',
    ...

Using your local IP Address into your configuration.

You can add the key "@@MY_IP_ADDRESS" to your configuration to load your local IP Address.

Eg.

API_URL : 'http://@@MY_IP_ADDRESS:8080'

key "@@MY_IP_ADDRESS" will replaced with Custom IP Address, if retrieving IP Address fails localhost will used.

NOTE:

  • The local IP Address of the system if fetched as default.
  • Custom IP Address can be set manually by passing arguments in the CLI.

API

Methods

nameargumentsdescription
Configon
constructor
configFilePattern:StringCreates an instance
var EnvConfig = require('configon');
var config = EnvConfig( './config/config.@@ENV.json' );
Key @@ENV denotes the environment name in the file path
buildenvironment:String(optional)
ipAddress:String(optional)
Builds the configuraation and apply all the changes to templates and export them in to the required location
addTemplatetemplateFile:String
outputFile:String
Add template file path and its destination path.
removeTemplatetemplateFile:StringRemoves detail of template file from the list of templates
setDefaultEnvenv:StringSets default environment for configuration

Available Keys

Keydescription
@@ENVName of the environment
@@APP_NAMEName of the application
@@APP_VERSIONVersion of the application
@@BUILD_DATEBuild date of the current build
@@MY_IP_ADDRESSYour local IP Address

Contribute

See the contribute file!

PRs accepted.

Any optional sections

License

MIT © Cinergix Pty Ltd.

Keywords

config

FAQs

Package last updated on 13 Mar 2017

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