sn-props

This package lets application users specify one or more URLs to JSON files
containing "application properties." After the files are read and
deserialized, a programmer supplied callback is executed. The module provides
a read() function which reads the command line arguments looking for the
string '--config'. The parameter following the config file is a file:, http:
or https: URI.

You can use multiple --config flags to specify multiple resources. Each
resource will be read in order and combined into a single object that is
passed to the callback.

I use this feature to separate hardware specific properties from application
specific properties. I usually have hardware specific properties (like IP
addresses and ports to listen on) in files on the filesystem while application
specific properties (names of DB servers, application timeouts, etc.) in http
resources on our internal net. This is useful if you're running the same
application on several different machines.

Installation

The easiest way to install this package is to use npm:

npm install sn-props

If you want to check out the source, use the git command:

git clone git://github.com/smithee-us/sn-props.git

Usage (for end users)

This package is intended to allow a node application user to do something like
this:

and then have the system will pull properties from both the local file and
the remote server (example.com), munge them together in the same object and
start the main body of the application.

The sn-props module will also scan the command line for other parameters
(identified by a leading "--".) Values following the parameter will be
passed to the props.read() call in the properties object. For instance:

node application.js --port 9001 --host 127.0.0.1

will pass the following object to the program through the props.read() call:

{
"port": "9001",
"host": "127.0.0.1"
}

Placing a slash ("/") in a property name will cause that property name to be
interpreted as a path into the properties object passwd with the props.read()
call. The following invocation:

The module uses "reasonable" defaults for http and https connections, but these
can be overridden by passing options to a new props object and calling the read()
function on it directly. For instance, the 'global' option defines a global
options file that is read after resources specified on the command line. This
code fragment reads properties from files or URLs specified in the command
line and then reads them from the file "/etc/sample.json".