title: Initialize nodejs module once, use many times
body: <p>I'm trying to pull out some code into my node.js app into a module. However, I'm running into an issue: the module requires some configuration that's generated during app startup. Is there an elegant way to initialize the module (by passing in the configuration) the first time it's require()d, but subsequent require() calls don't re-run the initialization?</p>
  
  <p>I could do something like have an init() function that I call manually the first time but never again, but that seems clunky and I'm wondering if there's a better pattern for it.</p>
  
  <p>edit: Here's what I'm doing right now, which feels clunky since doThings() isn't going to work if init() hasn't been called.</p>
  
  <pre><code>var config;
  
  function doThings() {
      // use config variable for something
  }
  
  function init(newConfig) {
      config = newConfig;
  }
  
  module.exports = {
      doThings: doThings,
      init: init
  }
  </code></pre>