ES6 Class and module.exports
<p>I am seeing this pattern these days for nodeJS implementation, where in we have the following code for my Module:</p>

<pre><code>class Foo {
  bar() {
    console.log('bar');
  }
}
module.exports = Foo;
</code></pre>

<p>Then when I do a require and finally say new to create an instance of the class.</p>

<pre><code>var Foo = require(./foo);
var myFoo = new Foo();
myFoo.bar();
</code></pre>

<p>This pattern according to me will keep creating multiple instances of class Foo, everytime it is called.</p>

<p>The other pattern could have been what i am used to where in my foo.js would be.</p>

<pre><code>module.exports = {
  bar: function() {
    console.log('bar');
  }
};
</code></pre>

<p>And then i just require and call bar.</p>

<pre><code>var foo = require(./foo);
foo.bar();
</code></pre>

<p>Question would these two behave the same? Will the second pattern keep creating objects everytime I require and call bar on the object?</p>

<p>Isn't creating singleton pattern a good idea in case 1 as we are used to in other languages, wherein we keep serving the same instance if it has already been created once?</p>