I am trying to follow the tutorial at the following link about extending modules in JS. https://www.guru99.com/node-js-modules-create-publish.html and the codes are
Tutorial.js
var exports=module.exports={};
exports.tutorial=function()
{
console.log("Guru99 Tutorial")
}
NodeTutorial.js
var Tutor=require('./Tutorial.js');
exports.NodeTutorial=function()
{
console.log("Node Tutorial")
function pTutor()
{
var PTutor=Tutor
PTutor.tutorial();
}
}
App.JS
var localTutor=require('./NodeTutorial.js');
localTutor.NodeTutorial();
localTutor.NodeTutorial.pTutor();
it give the error of
localTutor.NodeTutorial.pTutor(); is not a function
so I searched at this forum and found this same code syntax with same issue Extending Module in nodejs gives error and according to the answer, I changed the code to
this.pTutor = function(){
var PTutor=Tutor
PTutor.tutorial();
}
and
var localTutor = new require('./NodeTutorial.js');
localTutor.NodeTutorial();
localTutor.pTutor();
so what I would like to ask is the syntax of extending modules change or what is the problem here? Is the way from tutorial no longer work?