Chris Seymour
Chris Seymour

Reputation: 85785

Accessing app configurations in middleware

How do you access application configuration settings inside a middleware function with express? For example say I have the following contrived example which is defined it's own module and I want to branch based on the results of a application configuration.

function fail(req, res, next) {  
    if (app.config.fail === true) {
        res.json({'err': 'failed'});
    }
    return next();
}

What is correct way to handle this with express?

Upvotes: 2

Views: 103

Answers (1)

Dave Amit
Dave Amit

Reputation: 2309

Well, if you wanna access app inside a middleware you can do that with req.app. As explained here

I hope this is what you were looking for!

Upvotes: 1

Related Questions