Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

override with username based props

  • Loading branch information...
commit 3ad3199c914e12a7e489130c881987f1574236a0 1 parent 7055dc3
@robb1e robb1e authored
Showing with 18 additions and 5 deletions.
  1. +3 −3
  2. +15 −2 lib/properties.js
@@ -6,9 +6,9 @@ Node properties allows you to externalise configuration in a consistent manner u
From the root of your application (where the executing directory will be) create a folder called properties and a file within this called 'build.json'. Then in your application require this module and access your properties directly. An example is reading the port to start your application on:
var props = require('properties');
-# Future Scope
-I'd like to be able to get the current executing username and read a file called username.json and override any properties from the build file to allow simple local customisation.
+You can override properties by supplying a JSON file with the same name as the user who is executing the process, e.g. properties/robbieclutton.json. Any properties included here will overwrite those in the build.json file enabling local customisations.
17 lib/properties.js
@@ -1,12 +1,25 @@
var fs = require('fs');
-var baseProperties = process.cwd() + '/properties/build.json';
+var username = process.ENV['USER'];
+var base_properties_file = process.cwd() + '/properties/build.json';
+var user_properties_file = process.cwd() + '/properties/' + username + '.json';
var properties = {};
+var user_properties = {};
try {
- properties = JSON.parse(fs.readFileSync(baseProperties, 'utf8'));
+ properties = JSON.parse(fs.readFileSync(base_properties_file, 'utf8'));
} catch (err){
+try {
+ user_properties = JSON.parse(fs.readFileSync(user_properties_file, 'utf8'));
+} catch (err){
+ // do nothing and don't override
+for (attrname in user_properties) {
+ properties[attrname] = user_properties[attrname];
module.exports = properties;
Please sign in to comment.
Something went wrong with that request. Please try again.