Skip to content
This repository
Browse code

Added NODE_CONFIG_DIR environment variable

  • Loading branch information...
commit 23f012f8806a34faefb874c3181106cc49a9a6d4 1 parent 0aee036
Loren West authored
7 History.md
Source Rendered
... ... @@ -1,3 +1,10 @@
  1 +0.4.10 / 2012-01-18
  2 +===================
  3 +
  4 + * Made sure the CONFIG object is a shared singleton
  5 + * Added NODE_CONFIG_DIR environment variable to point to a different directory
  6 + * Added tests and documentation for the above
  7 +
1 8 0.4.9 / 2012-01-06
2 9 ==================
3 10
4 config/default.coffee
... ... @@ -1,4 +0,0 @@
1   -module.exports =
2   - AnotherModule: parm3: "value3"
3   - Customers:
4   - dbName: "from_default_coffee"
10 config/default.js
... ... @@ -1,10 +0,0 @@
1   -// Common configuration parameters
2   -module.exports = {
3   - TestModule: {
4   - parm1:"value1"
5   - },
6   - Customers: {
7   - dbHost:'base',
8   - dbName:'from_default_js'
9   - }
10   -};
8 config/default.json
... ... @@ -1,8 +0,0 @@
1   -{
2   - "Customers": {
3   - "dbName":"from_default_json"
4   - },
5   - "AnotherModule": {
6   - "parm1":"value1"
7   - }
8   -}
9 config/default.yaml
... ... @@ -1,9 +0,0 @@
1   -# Example of the baseline configuration in YAML
2   -
3   -Customers:
4   - dbPort: 5984
5   - dbName: from_default_yaml
6   -
7   -AnotherModule:
8   - parm2: value2
9   -
6 config/runtime.json
... ... @@ -1,6 +0,0 @@
1   -{
2   - "Customers": {
3   - "dbName": "override_from_runtime_json"
4   - },
5   - "watchThisValue": 54485
6   -}
4 config/test.yaml
... ... @@ -1,4 +0,0 @@
1   -# This is loaded if $NODE_ENV=test
2   -
3   -Customers:
4   - dbPort: 5999
7 lib/config.js
@@ -8,8 +8,9 @@ var Sys = require('sys'),
8 8 // Static members
9 9 var DEFAULT_CLONE_DEPTH = 6,
10 10 FILE_WATCHER_INTERVAL = 3000,
11   - CONFIG_PATH = process.cwd() + '/config/',
12   - runtimeJsonFilename = CONFIG_PATH + 'runtime.json',
  11 + DIR = 'NODE_CONFIG_DIR',
  12 + CONFIG_DIR = process.env[DIR] ? process.env[DIR] : process.cwd() + '/config/',
  13 + runtimeJsonFilename = CONFIG_DIR + 'runtime.json',
13 14 originalConfig = null, // Not including the runtime.json values
14 15 runtimeJson = {}, // Current runtimeJson extensions
15 16 isQueuedForPersistence = false,
@@ -568,7 +569,7 @@ Config.prototype._loadFileConfigs = function() {
568 569 baseNames.forEach(function(baseName) {
569 570 extNames.forEach(function(extName) {
570 571 // Try merging the config object into this object
571   - var fullFilename = CONFIG_PATH + baseName + '.' + extName;
  572 + var fullFilename = CONFIG_DIR + baseName + '.' + extName;
572 573 var configObj = t._parseFile(fullFilename);
573 574 if (configObj) {
574 575 t._extendDeep(t, configObj);
8 test/1-protected-test.js
@@ -4,6 +4,9 @@
4 4 * @module test
5 5 */
6 6
  7 +// Change the configuration directory for testing
  8 +process.env.NODE_CONFIG_DIR = __dirname;
  9 +
7 10 // Hardcode $NODE_ENV=test for testing
8 11 process.env.NODE_ENV='test';
9 12
@@ -12,9 +15,6 @@ var CONFIG = require('../lib/config');
12 15 var vows = require('vows');
13 16 var assert = require('assert');
14 17
15   -// These tests require the directory to be the root of the node-config project
16   -process.chdir(__dirname + '/..');
17   -
18 18 /**
19 19 * <p>Tests for underlying node-config utilities. To run type:</p>
20 20 * <pre>npm test config</pre>
@@ -254,7 +254,7 @@ exports.PrivateTest = vows.describe('Protected (hackable) utilities test').addBa
254 254
255 255 '_parseFile() tests': {
256 256 topic: function() {
257   - return CONFIG._parseFile(__dirname + '/../config/default.yaml');
  257 + return CONFIG._parseFile(__dirname + '/config/default.yaml');
258 258 },
259 259 'The function exists': function() {
260 260 assert.isFunction(CONFIG._parseFile);

0 comments on commit 23f012f

Please sign in to comment.
Something went wrong with that request. Please try again.