import winston from 'winston'
import fs from 'fs'

const configDefaults = {
  argsTransport: {
    level: 'warn',
    handleExceptions: true,
    timestamp: true,
    stringify: true,
    colorize: true,
    json: true
  }
}

export function getConfig() {
  const configPath = process.env.CONFIG_PATH || './config.json'
  const config = Object.assign(
    {}, configDefaults, JSON.parse(fs.readFileSync(configPath)))

  winston.configure({ transports: [
    new winston.transports.Console(config.argsTransport) ] })

  return config
}


import winston from 'winston'
import fs from 'fs'
import process from 'process'

const configDefaults = {
  argsTransport: {
    level: 'warn',
    handleExceptions: true,
    timestamp: true,
    stringify: true,
    colorize: true,
    json: true
  }
}

export function getConfig() {
  const configPath = process.env.CONFIG_PATH || process.argv[2] || './config.json'
  const config = Object.assign(
    {}, configDefaults, JSON.parse(fs.readFileSync(configPath)))

  winston.configure({ transports: [
    new winston.transports.Console(config.argsTransport) ] })

  return config
}


allow the config file to be specified as the only command-line arg to this program. It will be ignored in favor of an environment variable.