node-simple-config
v1.0.4
Published
Simplifies configuration loading
Downloads
4
Readme
Node Simple Config
Purpose
Simplifies loading of configuration file. Other modules seem to over-complicate it. Inspired by Laravel
Installation
npm install node-simple-config
Features
- Loads configuration parameters in key-value manner
- Reloads configuration file
Usage
.env
ENV=DEV
LOG_LEVEL=DEBUG
DB_HOST_NAME=database.some-dns.myserver.com
DB_HOST_PORT=6379
DB_HOST_DATABASE=Users
DB_HOST_PASSWORD=passwerd
example.js
// Loads config file from .env file
var config = require('node-simple-config');
var dbHost = config.get('DB_HOST_NAME');
var dbPort = config.get('DB_HOST_PORT');
console.log(dbHost); // database.some-dns.example.com
console.log(dbPort); // 6379
// Make changes to .env file
// Say we change the DB_HOST_NAME=anotherhost.com in .env file
config.reload();
var dbHost = config.get('DB_HOST_NAME');
console.log(dbHost); // anotherhost.com
What if you don't have .env file?
You can either:
- Create a symlink
ln -s path/to/env .env
OR
- Start the application with config path as such
node yourApp.js --config-path=path/to/env
Test
npm test