我正在编写一个Node.js应用程序,我正在尝试使用来自我的index.js文件中的函数。每当我添加
var IndexBot = require('/root/afstudeerwerk/chatbotPIROS/index');
对于我的calls.js文件,我收到以下错误:error1:
routes.js(/ root / gradu work / chatbotApi / api / routes):
'use strict';
module.exports = function(app) {
var chatbot = require('/root/afstudeerwerk/chatbotPIROS/calls');
app.post('/slack/receive',chatbot.create_a_message);
app.post('/DBcheck/:id',chatbot.checkUserAuth);
};
calls.js(/ root / gradu work / chatbotPIROS / calls)
'use strict';
exports.create_a_message = function(req, res) {
var IndexBot = require('/root/afstudeerwerk/chatbotPIROS/index');
var message = req.body;
var button = JSON.parse(message.payload).actions[0].value
if(button == 'MeanMakeVM'){
res.json({message:'Please enter your VM specs.'});
IndexBot.stuur_bot_bericht('dit is een testbericht.');
}
您在控制器中缺少任何已在路径文件文件中指定路由的方法。
在你的路线文件中,你有一个路线app.post('/DBcheck/:id',chatbot.checkUserAuth);
,但它在calls.js
中没有任何名为checkUserAuth的函数,这就是它给你错误的原因。
在调用文件中创建名为checkUserAuth的方法,您的错误将得到解决