我正在使用 nodejs 中的查询器制作 CLI。
因此,在每个选择列表中,我都必须给出退出选择,因此如果用户想退出,他/她可以轻松退出。
所以我必须一次又一次地编写 Exit 来避免这个问题,我创建了一个Exit.js文件并将 Exit 代码移到那里,这样我就可以一次又一次地使用代码。
退出.js
const executeQuery = require("../executeQuery");
function WantToExit() {
inquirer
.prompt([
{
name: "moreQuery",
type: "confirm",
message: "Want to do anything else?",
},
])
.then((answer) => {
if (answer.moreQuery) return executeQuery();
});
}
module.exports = WantToExit;
我的 executeQuery 代码看起来像这样
执行查询.js
const wantToExit = require("../Exit");
const Science = require("../Science");
function executetQuery() {
inquirer
.prompt([
{
type: "list",
name: "cmsType",
message: " Select Subject Options ",
default: false,
choices: ["Science", "Maths", "English", "Exit"],
},
])
.then((answers) => {
if (answers.cmsType === "Science") {
Science();
} else if (answers.cmsType === "Exit") {
wantToExit();
}
});
}
module.exports = executetQuery;
当我从executeQuery选项中选择Exit并按 Y选项时,我从Exit.js文件中收到此错误
if (answer.moreQuery) return executeQuery();
^
TypeError: executeQuery is not a function
at /home/admin/SchoolProject/src/Exit/index.js:13:36