当我使用“app.use”命令时,我的快速服务器遇到了一些问题
在我的 task-routes.js 文件中,我有以下代码
import express from 'express';
const router = express.Router();
router.post('/task',(req, res) => {
res.send('post.task - create a task');
});
router.get('/task',(req, res) => {
res.send('get.task - get all tasks')
});
router.get('/task/:id',(req, res) => {
res.send('get.task/:id - get task by id')
});
router.put('/task',(req, res) => {
res.send('put.task - update a task')
});
router.delete('/task',(req, res) => {
res.send('delete.task - delete a task')
});
export default router;
在我的 routes.js 文件中,我有这个
import taskRoutes from './api/task/tasks-routes';
export function registerRoutes(app) {
app.use('/api',taskRoutes);
}
索引.js
import express from 'express';
const app = express()
import {registerRoutes} from './routes';
const port = 3000
registerRoutes();
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`MEVN app listening at http://localhost:${port}`))
这是我不断收到的错误
/Users/musabhamid/Desktop/mevn-stack copy/prod-server/routes.js:15
app.use('/api', _tasksRoutes2.default);
^
TypeError: Cannot read property 'use' of undefined
at registerRoutes (/Users/musabhamid/Desktop/mevn-stack copy/prod-server/routes.js:15:7)
at Object.<anonymous> (/Users/musabhamid/Desktop/mevn-stack copy/prod-server/index.js:14:28)
皈依舞
慕容708150
相关分类