title: Pass variable from Express to Client JavaScript
body: <p>Ultimately I'm trying to pass JSON data from the Node server to be used by D3 in the client.</p>
  
  <p>Here's my index.js </p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  var portmix = require('../data/holdings.json');
  
  /* GET individual portfolio page. */
  router.get('/portfolio/:portcode', function(req, res) {
  
    var porthold = [];
    for(var i in portmix){
      if(portmix[i].PortfolioBaseCode === req.params.portcode){
          porthold.push(portmix[i])
    }}
  
    res.render('index', { 
      pagetype: 'single_portfolio',
      holdings: porthold[0]
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Here's the ejs file:</p>
  
  <pre><code>&lt;div class="portfolio"&gt;
  
      &lt;h2&gt;&lt;%= holdings.ReportHeading1 %&gt;&lt;/h2&gt;
      &lt;ul&gt;
          &lt;li&gt;Cash: &lt;%= holdings.CashMV %&gt;&lt;/li&gt;
          &lt;li&gt;Fixed Income: &lt;%= holdings.FixedMV %&gt;&lt;/li&gt;
          &lt;li&gt;Equity: &lt;%= holdings.EquityMV %&gt;&lt;/li&gt;
          &lt;li&gt;Alternatives: &lt;%= holdings.AltMV %&gt;&lt;/li&gt;
      &lt;/ul&gt;
  
      &lt;div class="chart"&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>It works to display the "holdings" values. However, if I try to call it from a client side js using:</p>
  
  <pre><code>console.log("Holdings: " + holdings);
  </code></pre>
  
  <p>The result is </p>
  
  <pre><code>Holdings: undefined
  </code></pre>
  
  <p>Is there a way to do this? Or am I going about it all wrong?</p>