Em meus roters crio:
var express = require('express');
var router = express.Router();
var service = require('./../services/users');
router.get('/login', service.login);
router.get('/register', service.register);
router.get('/edit/:id', service.edit);
module.exports = router;
Onde tem o service:
exports.login = function(req, res) {
res.render('login');
};
exports.register = function(req, res) {
res.render('register');
};
mas quando rodo o npm start
dá a mensagem de erro:
\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.(anonymous function) [as get] (C:\mean\parking\node_modules\express\lib\router\route.js:202:15)
at Function.proto.(anonymous function) [as get] (C:\mean\parking\node_modules\express\lib\router\index.js:510:19)
at Object.<anonymous> (C:\mean\parking\routes\users.js:7:8)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\mean\parking\app.js:9:19)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ramos\AppData\Roaming\npm-cache\_logs\2018-11-03T16_02_53_765Z-debug.log
** EDITADO - MEU APP.JS **
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
var connection = require('./models');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var cars = require('./routes/cars');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/cars', cars);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// 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;
Meu Packarge:
{
"name": "parking",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bootstrap": "^4.1.3",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"express-session": "^1.15.6",
"hbs": "~4.0.1",
"http-errors": "~1.6.2",
"mongoose": "^5.3.9",
"morgan": "~1.9.0"
}
}
O que posso estar fazendo de errado?