npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

propman

v0.1.3

Published

Property and config loader and manager, allowing you to load hierarchical property values based on environment variables

Downloads

27

Readme

propman

Simple property and config manager that allows you to load up your properties files and hierarchical variations of those properties files specific to individual environments. Can be used when you want to keep the management of your properties simple and local to the code instead of using external tools.

Can also be used for loading up text for internalization.

Example 1

You have two servers that you deploy your code to; PROD1 and PROD2. Both servers might need to point to different database instances. Both servers also share common properties like labels for form buttons.

appConfig.properties

db.url=dev.db.foo.com

appConfig.properties_en_UK

button1=submit button2=signin

appConfig.properties_en_UK_PROD1

db.url=prod1.db.foo.com

appConfig.properties_en_UK_PROD2

db.url=prod2.db.foo.com

In your node code, you do

var propMan = require('./propman').getInstance();
propMan.loadProperty('./directory/to/properties','appConfig.properties');

var dbServer = propMan.getProperty('appConfig.properties','db.url');

You can then use the following environment variable

PROPMANENV

to load the properties file specific to the environment your code is running on. So for PROD1 we can start the node instance as

PROPMANENV=en_UK_PROD1 node server.js

And this will load up the following properties files

appConfig.properties appConfig.properties_en_UK appConfig.properties_en_UK_PROD1

And the following properties value

db.url=prod1.db.foo.com button1=submit button2=signin

On PROD2 we would pass in PROPMANENV=en_UK_PROD2 which would then load

appConfig.properties appConfig.properties_en_UK appConfig.properties_en_UK_PROD2

with the following properties being loaded

db.url=prod2.db.foo.com button1=submit button2=signin

Example 2

You want to test the code locally on your development laptop but want to test it against a TEST database and a UAT database, maybe for troubleshooting or debugging

appConfig.properties

db.url=dev.db.foo.com

appConfig.properties_en_UK_TEST

db.url=test.db.foo.com

appConfig.properties_en_UK_UAT

db.url=uat.db.foo.com

You can then use

PROPMANENV=en_UK_TEST to load up the TEST db.url which will give you test.db.foo.com PROPMANENV=en_UK_UAT to load up the UAT db.url which will give you uat.db.foo.com

If you don't pass in any environment variable you will get the default which will be dev.db.foo.com

Example 3

You have a piece of text with word/s that need to be substituted by runtime value. You can specify runtime value substitution using {{}}

e.g.

frontpage.blurb=The quick {{colour}} {{animal}} jumped over the lazy {{animal2}}

Then in your code you can pass in a map that contains the actual value to put in.

var text = propMan.getProperty('propertyfile.properties','frontpage.blurb', {colour : 'brown', animal: 'fox', animal2: 'dog'});

You will end up with the text

The quick brown fox jumped over the lazy dog

Example 4

You can make sure a property must be set a value by using {{{required}}}. If the property hasn't been set after loading all the hierarchical properties files, an error will be thrown.

appConfig.properties

property.that.has.to.be.set={{{required}}} label1={{{required}}}

appConfig.properties_en_UK

property.that.has.to.be.set=UK specific value label1=press for lift

appConfig.properties_en_US

property.that.has.to.be.set=US specific value label1=press for elevator

If you just load appConfig.properties (i.e. without any PROPMANENV) it will throw an error as both properties has a value of {{{required}}}.

e.g.

var propMan = require('./propman').getInstance();

try {
    propMan.loadProperty('./directory/to/properties','appConfig.properties');
} catch (err) {
    // deal with err
    // you can get access to an object that has a map of all the properties that has been set {{{required}}} by using err.extra
    // e.g.
    console.dir(err.extra);
}

Extra

You can also pass in the PROPMANENV environment programmatically

var propMan = require('./propman').getInstance('en_UK_PROD1');