简体   繁体   English

错误:Route.get() 需要回调 function 但在 Node.js 中得到了一个 [object Undefined]

[英]Error: Route.get() requires a callback function but got a [object Undefined] in Node.js

I am getting the Error: Route.get() requires a callback function but got a [object Undefined]我收到错误:Route.get() 需要回调 function 但得到了一个 [object Undefined]

while running my app.js file.在运行我的 app.js 文件时。 I am following the freecodecamp tutorial "4 nodejs project", the error is in task manager app.我正在关注 freecodecamp 教程“4 nodejs 项目”,错误出现在任务管理器应用程序中。

my app.js我的应用程序.js

const express = require('express') 
const app = express()
 const tasks = require('./routes/tasks') //middleware

app.use(express.json())

//routes app.get('/hello',(req,res) => {
       res.send('task manager app')
})

app.use('/api/v1/tasks',tasks)

const port = 3000

app.listen(port,console.log(Server is listening on port ${port}...))

routes/tasks.js路线/tasks.js


const express = require('express')
const router = express.Router()

const { getAllTasks,
createTask,
getTask,
updateTask,
deleteTask, } = require('../controllers/tasks')

router.route('/').get(getAllTasks).post(createTask)
router.route('/:id').get(getTask).patch(updateTask).delete(deleteTask)

module.exports = router

controllers/tasks.js控制器/tasks.js


const getAllTasks = (req,res)=\> {

    res.send('all items')

}
const createTask = (req,res) =\> {
res.send('create task')
}
const getTask = (req,res) =\> {
res.send('get single task')
}
const updateTask = (req,res) =\> {
res.send('update task')
}
const deleteTask = (req,res) =\> {
res.send('delete task')
}
module.export = {
getAllTasks,
createTask,
getTask,
updateTask,
deleteTask,
}

no error should be there but throws the above error.

You are trying to get your controller function in your root for more details you can check out here moz您正在尝试在根目录中获取 controller function 以获取更多详细信息,您可以在此处查看moz

router.get('/',getAllTasks) //example

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:Route.get()需要回调函数,但得到了一个[object Undefined] NODE.JS + SQL - Error: Route.get() requires a callback function but got a [object Undefined] NODE.JS + SQL Node.js错误:Route.get()需要回调函数,但是得到了[object Undefined] - Node.js Error: Route.get() requires callback functions but got a [object Undefined] 节点:Route.get() 需要一个回调函数,但得到了一个 [object Undefined] - Node: Route.get() requires a callback function but got a [object Undefined] Node JS:Route.get() 需要一个回调函数,但在使用 ES6 模块时得到了 [object Undefined] - Node JS : Route.get() requires a callback function but got a [object Undefined] While using ES6 Modules 节点服务器错误:Route.get() 需要回调 function 但得到了 [object Undefined] - node server Error: Route.get() requires a callback function but got a [object Undefined] 错误:Route.get() 需要一个回调函数,但在 app.js 中得到一个 [object Undefined] - Error: Route.get() requires a callback function but got a [object Undefined] at app.js 错误:Route.get()需要回调函数,但得到了一个[object Undefined] - Error: Route.get() requires callback functions but got a [object Undefined] 错误:Route.get() 需要回调 function 但在使用导入的 function 时得到 [object Undefined] - Error: Route.get() requires a callback function but got a [object Undefined] while using imported function 错误连接 MongoDB:错误:Route.get() 需要一个回调函数,但得到一个 [object Undefined] - Error connection MongoDB: Error: Route.get() requires a callback function but got a [object Undefined] “错误:Route.get() 需要回调 function 但得到 [object Undefined]” 进行多次导出时 - “Error: Route.get() requires a callback function but got a [object Undefined]” when doing multiple exporting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM