在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)

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

express.js node.js

lgclan 9 years, 1 month ago

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

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

zlhhdyx answered 9 years, 1 month ago

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

帕萩莉诺蕾姬 answered 9 years, 1 month ago

Your Answer