在node.js中使用express做博客出错

本人菜鸟,才刚刚开始学习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)

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

阅读 9.3k
3 个回答

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

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

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

新手上路,请多包涵

如果用get或者post需要回调函数,你看一下你app.js里是不是则介样子app.get('/mobileEnd',routes.routeMobileEndCommonInter);
如果只是简单页面用app.use('/mobileEnd',routes)就不需要回调了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题