ini-parser-plus
A simple INI configuration file parser with support for .local files.
Installation
Using npm:
$ npm i --save ini-parser-plus
Usage
In myConfig.ini:
; general settings [general]force-ssl-port=443timezone="US/Pacific"country-timezones="US"lang="en" ; settings for ajax/javascript [ajax]server-timeout=25000 upload-timeout=2700000ajax-refresh=5000ajax-refresh-on-request-status=1000log=noautocomplete-search-delay=2000
In myConfig.ini.local:
Any new sections will be added to the config object and any redeclared section properties will override those set in myConfig.ini.
; general settings [general]timezone="US/Mountain" ; Overrides existing timezone property. locale="eu_US" ; Adds locale property. ; Adds an entirely new section. [debug]level=0
In Node.js:
// Load the parser.var config_parser = ; // Set the config path.config_parser; // Get all sections.var sections = config_parser; console; 'general' 'ajax' 'debug' // Get a specific section's properties.var properties = config_parser; console; 'force-ssl-port' 'timezone' 'country-timezones' 'lang' 'locale' // Load the config file into an object.var config = config_parser; console; general: 'force-ssl-port': '443' timezone: 'US/Mountain' 'country-timezones': 'US' lang: 'en' locale: 'en_US' ajax: 'server-timeout': '25000' 'upload-timeout': '2700000' 'ajax-refresh': '5000' 'ajax-refresh-on-request-status': '1000' log: 'no' 'autocomplete-search-delay': '2000' debug: level: '0' // Access the sections and their properties using Dot notation.console;US/Mountain // Access the sections and their properties using Bracket notation.console;25000
Exception Handling:
let config_parser = require('config-parser')(); try { config_parser.setConfigPath('./no/such/path/myConfig.ini'); } catch(e) { console.log(e.code +"::"+ e.message); } 2::No config file(s) found