title: Dynamic requires in nodejs before module.exports
body: <p>I have an app I'm working on that has active directory login and local login. When checking for permissions I want to allow permissions to either be set by AD group membership, or if not using AD then locally stored permissions in the database. As a result I have 2 different modules to handle permission checks. Is there a way to have a require at the top, before module.exports to be done dynamically through an if statement or something similar? I thought I could assign a process.env.isLocal and process from there but it doesn't seem to work I get an error that says Permissions is not defined</p>
  <pre><code>const moment = require('moment');
  const AdminPortal = require('../models/adminportal');
  if(process.env.isLocal) {
      const Permissions = require('../models/localLogin/localPermissions');
  } else {
      const Permissions = require('../models/permissions');
  }
  const isAuthenticated = require(&quot;../config/middleware/isAuthenticated&quot;);
  const config = require(&quot;../config/configFile.js&quot;).get(process.env.NODE_ENV.trim());
  module.exports = function(app){
  </code></pre>
  <p>I suppose maybe I need to have both code sets in one file and then choose which one to use based on if its a local login or not, I was just hoping to keep them separated.</p>