我在 Express.js 中有一个函数,使用 Node.js:
app.post("/checkExistsSpecific", function (req, res) {
// do some code
}
我还有另一个功能
app.post("/checkExistsGeneral", function (req, res) {
// do some code
// In this stage, I want to call /checkExistsSpecific API call
}
有没有办法在不使用 HTTP 调用的情况下从 app.post("/checkExistsGeneral"..)
调用 app.post("/checkExistsSpecific"..)
?
最佳答案
为了做到这一点,我认为您应该使用命名函数作为 POST 回调,而不是像当前那样使用匿名函数。这样您就可以在任何需要的地方引用它们。
类似于:
function checkExistsSpecific(req, res){
// do some code
}
app.post("/checkExistsSpecific", checkExistsSpecific);
app.post("/checkExistsGeneral", function (req, res) {
// do some code
// In this stage, I want to call /checkExistsSpecific API call
checkExistsSpecific(req, res);
}
最好。
关于javascript - 在js文件中调用Express.js的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27419014/