All files / config index.js

64.29% Statements 9/14
57.14% Branches 4/7
50% Functions 1/2
69.23% Lines 9/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x 1x           1x     8x 1x     8x     8x 43x             8x    
const extend = require('extend');  // deep clone, not like shallow Object.assign
const config = require('./config');
 
function isNumeric(num){
  return !isNaN(num)
}
 
module.exports = (user = {}) => {
 
  // If it's a number it's the port
  if (typeof user === 'number') {
    user = { port: user };
  }
 
  let options = extend(true, {}, config, user);
 
  // Overwrite with the env variables if set
  for (let key in options) {
    Iif (key.toUpperCase().replace(/\s/g, '_') in process.env) {
      let env = process.env[key.toUpperCase().replace(/\s/g, '_')];
      if (isNumeric(env)) env = +env;
      options[key] = env;
    }
  }
 
  return options;
}