title: Node.js ES6 classes with require
body: <p>So up until now, i have created classes and modules in <code>node.js</code> the following way:</p>
  
  <pre><code>    var fs = require('fs');
  
  var animalModule = (function () {
      /**
       * Constructor initialize object
       * @constructor
       */
      var Animal = function (name) {
          this.name = name;
      };
  
      Animal.prototype.print = function () {
          console.log('Name is :'+ this.name);
      };
  
      return {
          Animal: Animal
      }
  }());
  
  module.exports = animalModule;
  </code></pre>
  
  <hr>
  
  <p>Now with ES6, you are able to make "actual" classes just like this:</p>
  
  <pre><code>class Animal{
  
   constructor(name){
      this.name = name ;
   }
  
   print(){
      console.log('Name is :'+ this.name);
   }
  }
  </code></pre>
  
  <p>Now, first of all, i love this :) but it raises a question. How do you use this combined with <code>node.js</code>'s module structure?</p>
  
  <p>Say you have a class where you wish to use a module for the sake of demonstration say you wish to use <code>fs</code></p>
  
  <p>so you create your file:</p>
  
  <hr>
  
  <p><strong>Animal.js</strong></p>
  
  <pre><code>var fs = require('fs');
  class Animal{
  
   constructor(name){
      this.name = name ;
   }
  
   print(){
      console.log('Name is :'+ this.name);
   }
  }
  </code></pre>
  
  <p>Would this be the right way? </p>
  
  <p>Also, how do you expose this class to other files within my node project? And would you still be able to extend this class if you're using it in a separate file?</p>
  
  <p>I hope some of you will be able to answer these questions :) </p>