title: Understand the behavior of require in NodeJS
body: <p>I had two javascript files in Node Project.
  One was router which had routes and corresponding functions in it.
  Another was a utility class where commonly used functions are written as prototype. say utilservice.getSomething();</p>
  <p>The first file calls utilservice.getSomething() in second file.</p>
  <p>I imported the first file in second file (which is unnecessary and unused) .Then i called an API in first file.</p>
  <p>I got error 500 stating utilservice.getSomething() is not a function.</p>
  <p>I spent so much hours thinking something went wrong with use of Promise and tried with async and await and landed in same error.</p>
  <p>Very last, i removed the import and found API call happening well.</p>
  <p>I was with an impression that require is just for import of methods in another script. But there's something beyond it. There are resources online which would tell purpose of request. But i like to understand this behavior.</p>
  <p>Sample:</p>
  <p>File1.js</p>
  <pre><code>const utilService = require('../utils/utilService');
  
  router.get('/something',function(req,res){
    utilService.getSomething().then((data)=&gt;{
         //do something
   })
  });
  </code></pre>
  <p>File2.js</p>
  <pre><code>const file = require('../file1');
  
  function util(){}
  util.prototype.getSomething = function(){
    return &quot;hello&quot;
  }
  module.exports = new util();
  </code></pre>
  <p>I hit that /something API. I got utilservice.getSomething is not a function.</p>