properties-reader

Properties file reader for Node.js

npm install properties-reader
4 downloads in the last day
18 downloads in the last week
38 downloads in the last month

Properties-Reader

An ini file compatible properties reader for Node.JS

Installation

The easiest installation is through NPM:

npm install properties-reader

Or clone the repo https://github.com/steveukx/properties and include the /src/PropertiesReader.js script.

API

Read properties from a file:

var PropertiesReader = require('properties-reader');
var properties = PropertiesReader('/path/to/properties.file');

The properties are then accessible either by fully qualified name, or if the property names are in dot-delimited notation, they can be access as an object:

// fully qualified name
var property = properties.get('some.property.name');

// by object path
var property = properties.path().some.property.name;

To read more than one file, chain calls to the .read() method:

properties.read('/another.file').read('/yet/another.file');

To set an arbitrary property into the properties object, use .set():

properties.set('property.name', 'Property Value');

When reading a .ini file, sections are created by having a line that contains just a section name in square brackets. The section name is then prefixed to all property names that follow it until another section name is found to replace the current section.

# contents of properties file
[main]
some.thing = foo

[blah]
some.thing = bar

// reading these back from the properties reader
properties.get('main.some.thing') == 'foo';
properties.get('blah.some.thing') == 'bar';

Checking for the current number of properties that have been read into the reader:

var propertiesCount = properties.length;

The length is calculated on request, so if accessing this in a loop an efficiency would be achieved by caching the value.

When duplicate names are found in the properties, the first one read will be replaced with the later one.

Contributions

If you find bugs or want to change functionality, feel free to fork and pull request.

npm loves you