Skip to content
Advertisement

print SQL output in jade file

I’m trying to output an sql query in Jade file. I got it so far that I can print plain text to jade but when I try to put an output from SQL it doesn’t work can someone help me.

The code in app.js (NodeJS) :

con.query('SELECT * FROM user ', function(err, rows)
{
    console.log('Connection result error '+err);
    console.log('num of records is '+rows.length);
    //console.log(rows);

    res.render('index',
        { title : 'Home' }
    )
    res.render('index',
        { row : res.send(rows) }
    )
    console.log('num of records is '+rows.length);
});

The code in jade (What I have at the moment):

  - each row in rows
        p=row.first_names

Advertisement

Answer

You only need to call render once like this:

res.render('index', {
  title: 'Home',
  rows: rows
});

The single call contains the object with all of the values you want passed to the Jade template. Also note the change of the key row to rows since that is what you called it in your template, as well as not calling res.send inside of res.render

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement