How to implement inheritance in node.js modules?

node.js

Solution

With ES6 the usage of util.inherits() is discouraged in favor of ES6 class and extends

const EventEmitter = require('events');

class MyStream extends EventEmitter {
  constructor() {
    super();
  }
  write(data) {
    this.emit('data', data);
  }
}

const stream = new MyStream();

stream.on('data', (data) => {
  console.log(`Received data: "${data}"`);
});
stream.write('With ES6');

Problem

I am in process of writing nodejs app. It is based on expressjs. I am confused on doing inheritance in nodejs modules. What i am trying to do is create a model base class, let's say my_model.js. ``` module.exports = function my_model(){ my_model.fromID = function(){ //do query here } } ``` Now i want to use those methods in my_model in my other model class. let's say user_model.js How do i inherit my_model in user_model?

Original source