donald
donald

Reputation: 23767

ExpressJs: Config variables in different environments

Can't I define a variable to be used in different envs when I define the env?

app.configure 'development', () ->
 app.use express.errorHandler({dumpExceptions: true, showStack: true})
 mongoose.connect 'mongodb://xxx:[email protected]:10012/xxxx'
 test = "ola23"

app.configure 'production', () ->
 app.use express.errorHandler()
 mongoose.connect 'mongodb://xxx:[email protected]:10012/xxxx'
 test = "ola"

I can define the "mongoose.connect", why can't I define test?

Upvotes: 1

Views: 555

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187282

That code sets a local variable to that configuration function to a value. I'm sure that works. But how do you need to use that test variable?

The way you've done it here, it simply will go away as soon as this function finishes, you aren't sending or saving it anywhere. The mongoose.connect line, does something, it passes in a string to a function that uses that string to do something awesome. test = "ola" only sets a local variable.

So without knowing how you want to use test it's hard to advise more. But you probably want this instead:

app.set 'test', 'ola'

Which you can then retrive "ola" later with:

app.get 'test'

Upvotes: 1

Related Questions