Here are the fixes that you should make...
In the a.js file, you're exporting Render, however, it should be A instead...
class A {
constructor(name) {
this.name = name;
}
displayName() {
console.log(this.name);
}
}
module.exports = A;
In your common.js file, you have to export an object that consist of the common classes/functions/variables, or whatever, like the following:
const A = require('./a');
const someOtherVariable = 'Hello World!';
module.exports = {
A: A,
someOtherVariable: someOtherVariable,
};
Comment: the reason you "have to" is because you want to use the A class with the following syntax: common.A... Assuming the name of the file is common, you will probably export more than just that one class, so package them into an object...
Lastly, in the b.js file, you can then use the common.A syntax to extract the class you are looking to use...
const common = require('./common');
const a = new common.A('My name is khan');
a.displayName();
console.log(common.someOtherVariable); // Hello World!
Hope this helps.
common.jsmodule.exports = A