Consistent-configuration

Overview

In Node.js development, it is common that there are serveral envrionments like development, test, production and so. Corresponding to these envrioments are configurations differed from each other. Therefore, it is necessary to make these configuration consistently.

Using placeHolders

placeHolder is a signature indicating the place to be replaced by the specific envrioment value
in Bearcat, the placeHolder can be like this:

1
${car.num}

in car.js

1
2
3
4
5
var Car = function() {
this.$id = "car";
this.$Vnum = "${car.vnum}";
this.num = "${car.num}";
}

then in config.json file you can define car.num with the specific value

1
2
3
4
{
"car.num": 100,
"car.vnum": 101
}

then in car, $Vnum and num attributes will be injected with the right value in the config.json file, both styles are supported

Environment configuration

In Bearcat, you can write different environment configurations in the following structure:
directory structure

in directory named config, you put dev and prod sub-directory named by specific envrioment, and then write the specific configurations in these directory corresponding to each environment.

Switching environment

In Bearcat, you can switch different environment in the following ways:

1
node app.js env=prod
1
NODE_ENV=prod node app.js

by default, the env is dev