0

In Express 4.0, after declaring the server I do the following to set a server-wide variable...

var app = express();
app.set('foo', 'bar');

I don't see a method like that in Restify's documentation, so I'm just declaring an object inside the server that holds my variables.

Is that correct? Is there a better way to do this in Restify?

nacho_dh
  • 1,847
  • 3
  • 18
  • 27

1 Answers1

0

It sounds like that would work, but why not just create a module to hold your variables? Create a file named vars.js somewhere appropriate and make it like this:

module.exports = {
    my_var: 2112,
    other_var: 'signals'
}

Then wherever you need access to those variable just

var all_vars = require('./path/to/var.js');

and you'll have them.

HeadCode
  • 2,770
  • 1
  • 14
  • 26
  • I ended up doing just that and also passing some vars as environment variables, so I make sure I don't have any passwords hardcoded in the app. – nacho_dh Oct 07 '15 at 19:12