bluepuma77
bluepuma77

Reputation: 496

How to make variables available in routes and templates at the same time in node express?

I created an ssr node expressjs app with some client adjustable settings that are stored in a database. Examples are enable_feature_x='y' and url_logo='https://domain.tld/logo.png'.

Currently I load the variables in app.js, then I store them in app.locals and access them in the templates. But I somehow can't access them in routes. How can I access the app from within the routes?

I would like to be able to set them globally from app.js (on startup) and from an imported route (on update), and read them globally in any route and template.

I am sure this is a common problem, but I haven't found a solution yet. Any hints?

Upvotes: 0

Views: 39

Answers (1)

ryuken73
ryuken73

Reputation: 783

you can access app object by req.app in express router.

Upvotes: 1

Related Questions