title: How to use "require" dynamically in javascript?
body: <p>I have a javascript function in "sample.js" file. It is like this: </p>
  
  <p><code>var mapDict = { '100': 'test_100.js', '200': 'test_200_API.js', '300': 'test_300_API.js'  }</code></p>
  
  <pre><code>function mapAPI()
  {
      this.version = 0.1;
  }
  
  mapAPI.prototype.getFileName = function( id ) {
     return mapDict[id]
  }
  
  module.exports = mapAPI;
  </code></pre>
  
  <p>in another file named "institute.js" I want to require the above "test_xxx_API" files dynamically. I have the following code:</p>
  
  <pre><code>const mapAPI  = require('../../sample.js');
  const map     = new mapAPI();
  const mapFile = map.getFileName("100");
  var insAPI    = require(mapFile);
  </code></pre>
  
  <p>When I run this code by "node institute.js" command, I get the following error: </p>
  
  <pre><code>Error: Cannot find module './test_100_API.js'.
  </code></pre>
  
  <p>But the "test_100_API.js" file exists and is located in the current folder besides "institute.js". When I changed <code>var insAPI = require(mapFile);</code> to <code>var insAPI = require("./test_100_API.js");</code> and give it the exact path instead of dynamic path, it works fine. Can anyone help me?</p>
  
  <p>Thanks in advance</p>