@brevisstudios/config v1.0.1
Brevis Studios - Config
Easy no-dependency config library. Will load configuration from a json file. Offers methods to get, set and a middleware function to load the configuration into the views.
How to use
Import the module as early as possible. The module is self-loading, there is no need to explicitely call the load
method. Config file must exist in the current working directory (e.g. the root of your project).
Importing
import Config from '@brevisstudios/config'
Get
Use the static Config.get(key, defaultValue = null)
method to retrieve any key from the configuration. Key is case insensitive.
Set
Use the static Config.set(key, value)
method to retrieve any key from the configuration. Keys will automatically be uppercased.
Save
Call the static async Config.save()
method to save all data back to the config.json file.
Middleware
If using Express or similar frameworks, you can use the static express()
method as a middleware. This will expose the configuration to the views as variable config
.
app.use(Config.express());