1.0.3 • Published 5 years ago

config-importer v1.0.3

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
5 years ago

I've made this module in order to allow developers to create applications with the different work stages, such as production, testing, development, etc.

This module allows you to have a default configuration file and change its specific values according to your NODE_ENV variable.

How to use

To use this module with the default values, you just need to get the configuration like this:

const config = require('config-importer')()

If you want to change the options, you need to add options as an argument:

const options = {
    path: "configPath"
}

const config = require('config-importer')(options)

Options

You can leave the options empty. The default values are:

{
    "path": "config",   
    "default": "default",
    "debug": false
}
  • path: represents the directory where your configuration files are stored in relation to your project root directory.
  • default: represents the default configuration file name, without the .json extension.
  • debug: makes this module output debug log (i.e. config directory, thrown exceptions).

Example

In this scenario, you have your default configuration in config/default.json and you are running your application with NODE_ENV=dev npm start.

This module overwrites the values from default.json with the ones set on dev.json, as shown:

default.json

{
    "title": "Application title",
    "mongodb": {
        "uri": "https://productionhost:9999/db",
        "username": "username",
        "password": "password"
    }
}

dev.json

{
    "mongodb": {
        "uri": "https://devhost:9999/db",
        "extra": "param"
    }
}

Then, the configuration on your application should be:

{
    "title": "Application title",
    "mongodb": {
        "uri": "https://devhost:9999/db",
        "username": "username",
        "password": "password",
        "extra": "param"
    }
}
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago