title: How to import anonymous closure in NodeJS
body: <p>I am writing a nodejs script (that will be used in azure pipeline) to check that my Web developer didn't forget to regenerate object contracts used in the web application.
  So the goal is to read his file and compare objects within with the latest objects version stored somewhere else.</p>
  
  <p>The file appends a subobject in the global object (window in browser) within an anonymous function like 
  <a href="https://medium.com/@tkssharma/javascript-module-pattern-b4b5012ada9f" rel="nofollow noreferrer">https://medium.com/@tkssharma/javascript-module-pattern-b4b5012ada9f</a></p>
  
  <p>I tried the solution base on the "vm" module found here : <a href="https://stackoverflow.com/questions/5171213/load-vanilla-javascript-libraries-into-node-js">Load &quot;Vanilla&quot; Javascript Libraries into Node.js</a></p>
  
  <p>generatedModels.js</p>
  
  <pre><code>/***************************/
  /*  AUTO GENERATED via T4  */
  /***************************/
  (function(){
      "use strict";
  
      mynamespace = mynamespace || {};
      mynamespace.factories = mynamespace.factories || {};
      mynamespace.factories.models = mynamespace.factories.models || {};      
  
      mynamespace.factories.models.AdresseLibreModel_Factory = function() {
          return {"CodePays":null,"ComplementAdresse":null, /*...*/};
      };  
  })();
  </code></pre>
  
  <p>main.js</p>
  
  <pre><code>var vm = require("vm");
  var fs = require("fs");
  var data = fs.readFileSync("generatedModels.js");
  var window = {};
  vm.runInNewContext(data, window, "generatedModels.js");
  </code></pre>
  
  <p>Seems I can't use global object. 
  It always fails during "runInNewContext" 
  --> <strong>mynamespace is not defined</strong> 
      at generatedModels.js:9:2</p>
  
  <p>How can I use that file like it's used in browser?
  If needed, I can modify the T4 template to change the structure of the "generatedModels.js" file, but it still needs to be used by the browser.</p>