I'm trying to learn Node.js and currently I'm studying how to load/export modules and link codes between different files. I've come across this one function that I wrote that doesn't seem to show the intended output in my VS code terminal:
Here is the main handler that I wrote:
yargs.command({
command: "Read",
describe: "Reading the note",
builder: {
title: {
describe: "Note title",
demandOption: true,
type: "string",
},
body: {
describe: "Note body",
demandOption: true,
type: "string",
},
},
handler(argv) {
notesUtility.readNotes(argv.title);
},
});
And here is the module that I'm supposed to export to the handler:
const readNotes = function (title) {
const notes = loadNotes();
const note = function (note) {
if (note.title === title) {
console.log(chalk.inverse(note.title));
console.log(note.body);
} else {
console.log(chalk.red.inverse("Notes not found!"));
}
};
};
All the other modules that were perfectly fine and showing intended output into my terminal except for this one, I tried debugging it but even the debugger can't seem to pick up this part of the module. It's like it's invisible.
Any one who has an idea what's going on? I hope this question made sense to any one who will read it.
Seems like you do assign the function to the variable note but never call it. You need to invoke it, for example like this note(param)