在node.js中使用express做博客出错
巴扎黑
巴扎黑 2017-04-17 12:05:00
[Node.js讨论组]

本人菜鸟,才刚刚开始学习node.js,使用express时遇到错误,
Error: .get() requires callback functions but got a [object Undefined],
index.js中的代码为

module.express = function(app) {
app.get( '/', function (req, res) {
    res.render( 'index', {title: '主页' });
});
app.get( '/reg', function (req, res) {
    res.render( 'reg', {title: '注册' });
});
app.post( '/reg', function (req, res) {
});
app.get( '/login', function (req, res) {
    res.render( 'login', {title: '登录' });
});
app.post( '/login', function (req, res) {
});
app.get( '/post', function (req, res) {
    res.render( 'post', {title: '发表' });
});
app.post( '/post', function (req, res) {
});
app.get( '/logout', function (req, res) {
});

};
完整的错误代码为:
lu@lu-QSH4:~/node/blog_old1$ node app

/home/lu/node/blog_old1/node_modules/express/lib/router/index.js:290

throw new Error(msg);
      ^

Error: .get() requires callback functions but got a [object Undefined]

at /home/lu/node/blog_old1/node_modules/express/lib/router/index.js:290:11
at Array.forEach (native)
at Router.route (/home/lu/node/blog_old1/node_modules/express/lib/router/index.js:286:13)
at Router.(anonymous function) [as get] (/home/lu/node/blog_old1/node_modules/express/lib/router/index.js:308:16)
at Function.app.(anonymous function) [as get] (/home/lu/node/blog_old1/node_modules/express/lib/application.js:412:26)
at Object.<anonymous> (/home/lu/node/blog_old1/app.js:42: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)

求大神指点一二啊!!要崩溃了-_-||

巴扎黑
巴扎黑

全部回复(2)
天蓬老师

请问你出错的代码是那一行?可以标下行号:)
哪一行是290

还有一点是你的第一行代码怎么是 module.express?

ringa_lee

这错误比较清楚Error: .get() requires callback functions but got a [object Undefined],意思是.get方法期待一个回调函数,而你给了一个undefined
好好检查下你的代码吧,骚年!

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号