Well I'm trying to get into Node.js / Express.js – however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim).
However, I'm now getting the following errors:
Express 500 SyntaxError: Unexpected identifier * at Object.Function (unknown source) * at Object.compile (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/jade.js:230:10) * at ServerResponse._render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:368:22) * at ServerResponse.render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:234:17) * at Object. (/home/duncan/helloExpress/app.js:46:7) * at nextMiddleware (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:139:34) * at param (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:147:16) * at pass (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:155:10) * at Object.router [as handle] (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:161:6) * at next (/usr/local/lib/node/.npm/connect/1.4.0/package/lib/http.js:204:15)
My app.js code is as follows:
Declare the users array of object
var users = [ { name: 'Duncan', email: 'duncan@email.com'}, { name: 'Bob', email: 'bob@email.com'} ];
and…
the bit that calls and renders the new users.jade
app.get('/users', function(req, res){ res.render('users', { users: users }); });
I don't know if I'm just being blind today, but I would really like to get this example working.
NB. app.js 46:7 is the 'res.render' char 7 is the . between res and render. – from the error message.
The users.jade file is as follows:
h1 Users ul#users - each user in users li= user.name
If I get rid of the:
user in users
and li= user.name
it renders the page, as soon as I add them, it gives me the above error message, and says there is something wrong with res.render('users' – on the dot (46:7).
PS. I'm following the second tutorial on here: http://expressjs.com/screencasts.html
My indentation:
[indent] - [indent] each user in users [indent][indent] li= [indent] user.name
Best Answer
You need to indent the
li= user.name
another level down from the each statement.This should work: