I am new to JavaScript / Nodejs. How can I share my configuration in a Nodejs application. For example: I haveconfig/config.coffee
path = require("path")
module.exports = {
development:
db: 'mongodb://localhost/hello'
root: rootPath = path.normalize(__dirname + '/..')
}
I included config.coffeein mine app.coffee.
express = require("express")
env = process.env.NODE_ENV || 'development'
config = require("./config/config")[env]
require('./config/boot')
app = express()
Now I want to include the variable configin mine config/boot.coffee. How can I do it? I do not want to re-incorporate config/config.coffeein config/boot.coffee. Here is my file config/boot.coffee:
env = process.env.NODE_ENV || 'development'
config = require("./config")[env]
fs = require("fs")
mongo = require("mongoose")
mongo.connect config.db
models_path = config.root+"/app/models"
fs.readdirSync(models_path).forEach( (file)->
require(models_path + '/' + file) if ~file.indexOf('.coffee')
)
services_path = config.root+"/app/services"
fs.readdirSync(services_path).forEach( (file)->
require(models_path + '/' + file) if ~file.indexOf('_service.coffee')
)
Sorry for the bad English :(
source
share