sn-props
v1.0.1
Published
Read properties from multiple URIs provided on the command line.
Downloads
4
Maintainers
Readme
sn-props
Read Application Properties from local files or http resources (formerly node-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:
If you want to check out the source, use the git command:
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:
will pass the following object to the program through the props.read() call:
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:
will pass the following object to the program through the props.read() call:
Usage (for developers)
To use the module, simply import the package can call the read() function. Ex:
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".
License
This package is released under a MIT license, the text of which may be found at https://github.com/smithee-us/sn-props/raw/master/LICENSE .