G:\workspace\Test2\node_modules\express\lib\router\index.js:252 throw new Error(msg); ^ Error: .get() requires callback functions but got a [object Undefined] at G:\workspace\Test2\node_modules\express\lib\router\index.js:252:11 at Array.forEach (native) at Router.route (G:\workspace\Test2\node_modules\express\lib\router\index.js:248:13) at Router.(anonymous function) [as get] (G:\workspace\Test2\node_modules\express\lib\router\index.js:270:16) at Function.app.(anonymous function) [as get] (G:\workspace\Test2\node_modules\express\lib\application.js:414:26) at Object.<anonymous> (G:\workspace\Test2\app.js:52:5) at Module._compile (module.js:456:26) at Object.Module._extensions…js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12)
正在做node.js开发指南中 注册和登入 一节的错误 一开始出了一个has no method 'router’的错误, 更改app.use(express.router(routes))为app.use(app.router),并添加routes(app)方法 然后就出现了上诉错误,请各位帮助一下啊
问题解决,原因是作者在书中漏说了一个步骤:在app.js
中删除下面的几行代码即可。
app.get('/', routes.index);
app.get('/u/:user', routes.user);
app.post('/post', routes.post);
app.get('/reg', routes.reg);
app.post('/reg', routes.doReg);
app.get('login', routes.login);
app.post('login', routes.doLogin);
app.get('logout', routes.logout);