To create global variables accessible in all views using Express and Node.js, we set the app.locals
property.
For instance, we write
app.locals.baseUrl = "http://www.example.com";
to set the app.locals.baseUrl
property to the value we want.
Then we can get the value in our middlewares with
const baseUrl = req.app.locals.baseUrl;