Load configuration, support process env, default value, file module configuration.
npm install sweet-config``bash`
npm install sweet-config
mkdir config
vi config/application.json
mkdir config/env
vi config/env/development.js
vi config/env/production
`javascript`
// application.json
{
"keys": ["abc", 'def']
}
`javascript`
// env/development.js
module.exports = {
database: {
host: 'localhost'
}
}
`javascript
// env/production
module.exports = {
database: {
host: '127.0.0.1'
}
}
`
`javascriptconfig
const config = require('sweet-config')
config.load() // if not give directory or file path, will load directory in project root``
config.get('application.keys') // should equals to ['abc', 'def']
// sweet config will load env configuration in root
config.get('database') // should equals to {host: '127.0.0.1'} when NODE_ENV=production