Express.js, Node.js Jade vim


Question

Help, before I throw my beautiful, expensive MacBook Pro to the ground in a fit of annoyance.

I'm trying to get something working in Expressjs, and it's really getting on my nerves. I'm following the tutorial on: expressjs.com/screencasts.html

Screencast 2:

And I'm getting this error message:

Express
500 Error: /home/duncan/helloExpress/views/users.jade:4 2| p#users 3| - each user in users > 4| li user.name 5| expected "indent", but got "newline"

    * 2| p#users
    * 3| - each user in users
    * > 4| li user.name
    * 5|
    *
    * expected "indent", but got "newline"
    * at Object.expect (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:131:13)
    * at Object.parseBlock (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:330:10)
    * at Object.parseEach (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:289:64)
    * at Object.parseExpr (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:175:21)
    * at Object.parseBlock (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:335:25)
    * at Object.parseTag (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:425:26)
    * at Object.parseExpr (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:163:21)
    * at Object.parse (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/parser.js:114:25)
    * at parse (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/jade.js:179:62)
    * at Object.compile (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/jade.js:224:7)

Please help, I get that it's getting a newline when it's expecting an indent by why? And how do I fix the blooming thing!!

My users.jade is as follows:

h1 Users
p#users 
    - each user in users
    li user.name

------------------


SO NOW THE ISSUE IS...


OK so now, it's been pointed out that I should be using a ul instead of a p (paragraph) element - pretty obvious once you notice it, though the error message, could be better.

However, I'm now getting the following errors: Though I'm now getting the following error:

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:

var users = [
    {   name: 'Duncan', email: 'duncan@email.com'},
    {   name: 'Bob',    email: 'bob@email.com'}
];

and...


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.

1
1
5/1/2011 9:00:02 AM

Accepted Answer

I changed the p to a ul (p tags shouldn't have children). And I defined the users array in the jade ( which works well for testing ).

note the indentation after the - each and the li=.

- users = [ { name:'Duncan' }, { name: 'Henry'}, { name: 'Raynos' } ]
h1 Users
ul#users 
  - each user in users
    li= user.name
4
4/30/2011 8:32:30 PM

ul
    - each item in sidebars
        li
          a(href=item.href,target='_self') !{item.name}

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon