sentaku
v0.2.0
Published
A simple, minimalist config manager
Downloads
3
Maintainers
Readme
Sentaku
sentaku (Japanese) -- noun -- selection; choice; option
A simple, minimalist config manager for Node.js projects.
Installing
$ npm i --save sentaku
Why Sentaku
One of the simplest ways to use a config in a Node.js project is to require a config.js
file that exports a JS object:
// config.js
module.exports = {
key: 'value',
simple: true
}
// app.js
var conf = require('./config.js')
console.log(conf.simple)
Sentaku is that, plus support for NODE_ENV
-specific configs and a little pathing goodness.
This approach has numerous benefits:
- Configuration as code -- configs are JS objects, so you can do javascript-y things like generating keys with getters
- No synchronous filesystem reads to find and access configs
- No parsing libraries to turn your configs into a native javascript object for consumption... because your configs are already a native javascript object
Sentaku is intentionally minimalist. If you would like more features in your config manager, I encourage you to check out the many great configuration modules out there.
Using Sentaku
// node_modules/sentakuConfs/default.js
module.exports = {
key: 'val'
}
// any file in app
var conf = require('sentaku')
- Put configs in
node_modules/sentakuConfs
(or symlink that path to your config dir) - Default config values in
default.js
- Env-specific overrides in
{env}.js
-- no fuzzy-matching, soNODE_ENV=dev
matchesdev.js
notdevelopment.js
- Sentaku assumes
NODE_ENV
isdev
unless otherwise specified
- Sentaku assumes
- Access config values with property accessors
If you've ignored the entire node_modules
directory with .gitignore
, you'll likely want to amend that so sentakuConfs
gets committed:
# .gitignore
node_modules/*
!node_modules/sentakuConfs
Regarding Security, Configs, and Version Control
Don't put private info (e.g. your AWS Secret Key) in version-controlled configs that might end up in public repos.
If you commit sensitive info to any public repo, consider it compromised. If this happens, you should always generate a new key or password. You can mitigate the damage by following GitHub's instructions here, but even then you should still probably generate a new key or password.
For open-source projects that interact with private apis/keys/passwords, consider creating a default.js.example
in your config dir with blank values and committing that file while adding your actual default.js
to your .gitignore
.
License
Mit. See license.