title: Display dynamically an image using express and EJS
body: <p>I have a collection containing different URLs of images. I retrieve the URL I want and want to pass it to the jade template like:</p>
  
  <pre><code>app.get('/',function(req,res){
      mongoDB.getUsedHomePageOne(function(err, result){
          if(!err){
              console.log("getUsedHomePageOne : ");
              console.log(result);
              app.locals['homePageImg'] = result.url;
          }
      });
  
      app.render('userPageEjs.html',function(err,renderedData){
          console.log(renderedData);
          res.send(renderedData);
      });
  });
  </code></pre>
  
  <p>and the getUsedHomePageOne looks like:</p>
  
  <pre><code>DBMongo.prototype.getUsedHomePageOne  = function(callback){
      this.homePageColl.findOne({used:1}, callback);
  };
  </code></pre>
  
  <p>and in the jade template:</p>
  
  <pre><code>&lt;img src="&lt;%= homePageImg %&gt;"/&gt;
  </code></pre>
  
  <p>So this won't work except if I load twice the page, I assume because it gets cached and is computed quickly enough or something.</p>
  
  <p>What is the proper way of doing it?</p>
  
  <p>PS: the 2nd time I load the page, everything will load correctly.</p>
  
  <p>PS2: I don't want to delay the rendering for the image, I would like to load the image once it is ready, but render the HTML page before anyway.</p>