【问题标题】:Node.js function not showing output in my Visual studio code terminalNode.js 函数未在我的 Visual Studio 代码终端中显示输出
【发布时间】:2021-09-24 07:20:15
【问题描述】:

我正在尝试学习 Node.js,目前我正在研究如何在不同文件之间加载/导出模块和链接代码。我遇到了我编写的这个函数,它似乎没有在我的 VS 代码终端中显示预期的输出:

这是我编写的主要处理程序:

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);
      },
   });

这是我应该导出到处理程序的模块:

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!"));
        }
       };
     };

除了这个之外,所有其他模块都非常好并且在我的终端中显示了预期的输出,我尝试调试它,但即使调试器似乎也无法获取模块的这一部分。就像是看不见一样。

有人知道发生了什么吗?我希望这个问题对任何阅读它的人都有意义。

【问题讨论】:

    标签: javascript node.js visual-studio-code event-handling


    【解决方案1】:

    似乎您确实将函数分配给变量 note 但从不调用它。你需要调用它,例如像这样note(param)

    【讨论】:

    • 我应该在哪里调用它?因为我也试过调用它,但还是不行。
    猜你喜欢
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 2019-04-03
    • 2018-10-01
    • 2021-01-31
    • 2022-08-18
    • 2021-09-05
    • 1970-01-01
    相关资源
    最近更新 更多