looking at code from https://github.com/twilson63/express-coffee/blob/master/src/config/index.coffee#L13 has the following:
#### Config file
# Sets application config parameters depending on `env` name
exports.setEnvironment = (env) ->
console.log "set app environment: #{env}"
switch(env)
when "development"
exports.DEBUG_LOG = true
exports.DEBUG_WARN = true
exports.DEBUG_ERROR = true
exports.DEBUG_CLIENT = true
exports.DB_HOST = 'localhost'
exports.DB_PORT = "3306"
exports.DB_NAME = 'mvc_example'
exports.DB_USER = 'root'
exports.DB_PASS = 'root'
when "testing"
exports.DEBUG_LOG = true
exports.DEBUG_WARN = true
exports.DEBUG_ERROR = true
exports.DEBUG_CLIENT = true
when "production"
exports.DEBUG_LOG = false
exports.DEBUG_WARN = false
exports.DEBUG_ERROR = true
exports.DEBUG_CLIENT = false
else
console.log "environment #{env} not found"
when i try to output the modules.export i get an empty array from the console!
how does one correctly make use of exports.DB_NAME if for example i have a module that needs this info?
console.log config.DB_NAME returns an undefined if called from another module.
any advice much appreciated.
Any property set on exports is available as a property of the object that is returned when you require the particular module. However, in this case, only one property is set at first: the setEnvironment function. The rest is simply undefined at first.
Use it like this:
config = require "./config" # the right path depends on where you're requiring from
config.setEnvironment "development" # or "testing", "production"
console.log config.DEBUG_LOG
console.log config.DB_Name