ExpressJs:在不同的环境中configurationvariables

当我定义env时,我不能定义一个在不同的envs中使用的variables吗?

app.configure 'development', () -> app.use express.errorHandler({dumpExceptions: true, showStack: true}) mongoose.connect 'mongodb://xxx:xxx-db2011@sun.memberd.mongohq.com:10012/xxxx' test = "ola23" app.configure 'production', () -> app.use express.errorHandler() mongoose.connect 'mongodb://xxx:xxx-db2011@sun.memberd.mongohq.com:10012/xxxx' test = "ola" 

我可以定义“ mongoose.connect ”,为什么我不能定义test

该代码将该configuration函数的局部variables设置为一个值。 我敢肯定,这是可行的。 但是,您如何使用该testvariables?

你在这里完成的方式,只要这个函数结束,它就会消失,你不会发送或保存在任何地方。 mongoose.connect行做了一些事情,它将一个string传递给一个函数,该函数使用该string来做一些很棒的事情。 test = "ola"只设置一个局部variables。

所以不知道如何使用test ,很难提供更多build议。 但是你可能需要这个:

 app.set 'test', 'ola' 

然后你可以通过以下方式回顾"ola"

 app.get 'test'