Sergei Basharov
Sergei Basharov

Reputation: 53850

How to access app object from a module in ExpressJS?

I run an Express app like this inside app.js file:

var app = express();

Now I can set some variables like this:

app.set('host', 'myhost')

I also have api.js module and I want to access this host variable from the root app.js file. How can I do this?

Upvotes: 1

Views: 1173

Answers (1)

abject_error
abject_error

Reputation: 2938

In your app.js file:

module.exports = app;

In your api.js file:

app = require("./app.js")
host = app.get('host');

Upvotes: 2

Related Questions