SyntaxError在我的node.js Express代码中

所以我试图按照这个教程video:

http://nodetuts.com/tutorials/13-authentication-in-express-sessions-and-route-middleware.html#video

正因为如此,我已经得到了这个代码在我的routes/index.js文件的顶部:

 var todo = require('../todo'); //line 1 //line 2 //new session //line 3 exports.newSession = function (req, res) { //line 4 res.render('sessions/new', { //**line 5** locals: { redir: req.query.redir } }); }; 

但是,当我运行我的应用程序,并触发routes.newSession处理程序,我得到这个错误:

 500 SyntaxError: Unexpected identifier at Object.Function (unknown source) at Object.compile (/home/admin73464/todo/node_modules/jade/lib/jade.js:161:8) at Function.compile (/home/admin73464/todo/node_modules/express/lib/view.js:65:33) at ServerResponse._render (/home/admin73464/todo/node_modules/express/lib/view.js:414:18) at ServerResponse.render (/home/admin73464/todo/node_modules/express/lib/view.js:315:17) at /home/admin73464/todo/routes/index.js:5:6 at callbacks (/home/admin73464/todo/node_modules/express/lib/router/index.js:272:11) at param (/home/admin73464/todo/node_modules/express/lib/router/index.js:246:11) at pass (/home/admin73464/todo/node_modules/express/lib/router/index.js:253:5) at Router._dispatch (/home/admin73464/todo/node_modules/express/lib/router/index.js:280:4) 

我没有看到我的index.js文件中的任何语法错误; 你做? 我应该去别的地方看吗?

提前致谢!

编辑:这里是我的views / sessions / new.jade文件的内容:

 h1 Login form(action='/sessions', method='POST') input(type='hidden', name='redir', value=redir) p label(for='login') Login: input(type='text' name='login', id='login') p label(for='password') Password: input(type='password' name='password', id='password') p input(type='submit') 

我很确定我抄袭了佩德罗写的东西。

第二次编辑:我也使用了一个layout.jade文件。 这里是:

 !!! html head title Our ToDo App link(rel='stylesheet', href='/stylesheets/style.css') body!= body 

根据受访者的build议,我试过从new.jade中删除所有(除了第一行)。 我得到了同样的错误。 我也尝试删除layout.jade中的所有行,也删除最后一行(body!= body)。 同样的错误。

感谢迄今为止所做的所有答复,我很高兴为您提供的帮助和build议。

第三编辑:我已经张贴我的应用程序的文件夹和文件

http://www.miramontestequila.com/todo/

我使用的目录结构是Express的默认设置,因此应该是不言自明的。

在你的new.jade文件中,你有行

 input(type='text' name='login', id='login') input(type='password' name='password', id='password') 

您在typename属性之间缺less逗号。 请记住,在Jade中,您必须在HTML属性之间插入逗号。

你的sessions/new.jade视图可能有问题吗?

你可以像这样改变index.js的内容,并告诉我这是否修复了一些事情:

 exports.newSession = function (req, res) { var redir = (req.query && req.query.redir) || ''; res.render('sessions/new', { redir: redir }); };