title: how to add custom function to express module
body: <p>I am trying to add a method
  loadSiteSettings to express module</p>
  
  <pre><code>     In app.js
  
  
          var express = require('express');
          var path = require('path');
          var mongoose = require('mongoose');
  
          //Set up default monggose connection for mongo db
          var mongoDB = 'mongodb+srv://***:*****@cluste******j.mongodb.net/cms?retryWrites=true&amp;w=majority';
          mongoose.connect(mongoDB,{useNewUrlParser: true});
          //Get the default connection
          var db = mongoose.connection;
  
          //Bind connection to error event (to get notification of connection errors)
          db.on('error',console.error.bind(console, 'MongoDB connection error:'));///????????
  
          var app = express();
  
  ///////////////////////////////////////////////////////////
         var indexRouter = require('./routes/index');
  
          app.loadSiteSettings = async function()
          { 
            let setting = await db.collection('settings').findOne();
            app.locals.siteSettings = setting;
          }
  
          app.loadSiteSettings();
  //////////////////////////////////////////////////////
          module.exports = app;
  
  
  </code></pre>
  
  <pre><code>
  Index.Js for router
  
  var express = require('express');
  var router = express.Router();
  var app = require('../app');
  var util = require('util');
  /* GET home page. */
  router.get('/', function(req, res, next) {
    res.render('index');
  });
  ///////////////////////////////////////////
  router.get('/reloadSettings', function(req,res,next){
      app.loadSiteSettings();
  })
  ///////////////////////////////////////
  
  module.exports = router;
  </code></pre>
  
  <p>so problem lies here, when server start it calls app.loadSiteSettings() in app.js
  but when i use route '/reloadSettings' it seems app is undefined in index.js</p>