Ошибка: Route.get () требует функции обратного вызова, но получил [объект Undefined] Я пытаюсь запустить приложение на VS-коде и получаю это сообщение
/home/unkown/Node/node_modules/express/lib/router/route.js:202
throw new Error(msg);
^
Error: Route.get() requires a callback function but got a [object Undefined]
at Route.<computed> [as get] (/home/unkown/Node/node_modules/express/lib/router/route.js:202:15)
Я обновляю пакеты до последней версии и перезапускаю порты, но все же покажите мне эту ошибку. где, черт возьми? Пожалуйста,
Мой код
Узел / приложение. js
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const index = require('./app_server/routes/index');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'app_server', 'views'));
app.set('view engine', 'pug');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Узел / app_server / контроллеры / местоположения. js
/* GET 'home' page */
const homeList = (res, req)=>{
res.render('index', {title: 'Home'})
};
/* GET 'Location info' page */
const locationInfo = (res, req)=>{
res.render('index', {title: 'Location Info'})
};
/* GET 'Add review' page */
const addReview = (res, req)=>{
res.render('index', {title: 'Add Review'})
};
module.exports = {
homeList,
locationInfo,
addReview
};
Узел / app_server / router / index. js
const express = require('express');
const router = express.Router();
const ctrlLocations = require('../controllers/locations');
const ctrlOthers = require('../controllers/others');
/* Locations pages */
router.get('/', ctrlLocations.homelist);
router.get('/location', ctrlLocations.locationInfo);
router.get('/location/review/new', ctrlLocations.addReview);
/* Other pages */
router.get('/about', ctrlOthers.about);
module.exports = router;