How to res.json and res.render at the same time, pass mongo db to angularjs?
<p>I use express, which comes with jade template engine.
<strong>app.js</strong></p>

<pre><code>// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
</code></pre>

<p>for each template, I will need to have <code>res.render</code> to have the html header rendered, if I don't use <code>res.render</code>, the template/page won't show. <strong>routes/index.js</strong></p>

<pre><code>router.get('/', function(req, res, next) {
    res.render('index', { title: 'Bookshop' });
});

router.get('/data', function(req, res, next) {
    res.render('data', { title: 'Bookshop | Categories' });
});

router.get('/items', function(req, res, next) {
    res.render('items', { title: 'Bookshop | Items' });
});
</code></pre>

<p>in <strong>app.js</strong> I've got my MongoDB set up correctly. </p>

<pre><code>var mongojs = require('mongojs');
var db = mongojs('book', ['books']);
</code></pre>

<p>What I am going to achieve is to pass MongoDB database to angular, then loop in jade file. <strong>myscript.js</strong></p>

<pre><code>app.controller('appCtrl', function ($scope, $http) {
   $http.get('/data').then(function(res){
        console.log(res.data);
        $scope.books = res.data;
    });
});
</code></pre>

<p><strong>data.jade</strong> file looks like this</p>

<pre><code>p(ng-repeat="item in books")
    span {{item.name}}
    span {{item.barcode}}
    span {{item.price}}
</code></pre>

<p>Right now I am stuck on how to pass database to <strong>myscript.js</strong>. I am unable to do this way in <strong>app.js</strong></p>

<pre><code>router.get('/data', function(req, res, next) {
    var db = req.db;
     db.zero.find(function (err, docs) {
        res.json(docs)
    });
});
</code></pre>

<p>the reason is jade template is being used, and need to use <code>res.render</code> to get the page showed correctly, however if I use <code>router.get('/data', function(req, res, next) {
        res.render('data', { title: 'Bookshop | Categories' });
    });</code> I am unable to pass database. </p>

<p>I understand I am unable to use res.render and res.json the at same time. is there a solution for pass database to angular? or do I have to convert jade to html? I am sure if I use html file I can use <code>res.json</code></p>

<p>Thanks</p>