title: Parse: JavaScript Promises issue
body: <p>I am trying to wrap my head around Promises, <code>then</code> , <code>when</code>, and everything else that goes along with it. I am not having much success. Here is what I'm trying to accomplish in English, and maybe somebody can crack the code because so far nothing I've written works.</p>
  
  <p>I am writing a SPA (single page app) for mobile devices. Essentially all the content is is one giant HTML page with a bunch of DIV's. However, only one DIV is shown at a time. The user will have a tab bar to click on each of the icons to show/hide DIV's. Think of something like the Apple App Store interface with "Featured", "Top Charts", "Explore", "Search", and "Updates" at the bottom.</p>
  
  <ol>
  <li>Parse database query of table <code>Businesses</code> for 1 business with <code>AppUrl=example.com</code></li>
  <li>Resulting business <code>objectId</code> is used to query table <code>Navigation</code> for all pieces of the navigation. Things like "Home", "About Us", "Menus", "Events", "Contact", etc.</li>
  <li>Resulting navigation items are looped to render DIV's with content in them. The content comes from the tables below depending on the <code>Module</code> column:
  <ul>
  <li>"Home" = <code>Photos</code> table</li>
  <li>"About Us" = <code>Pages</code> table</li>
  <li>"Menus" = <code>Lists</code> table</li>
  <li>"Event" = <code>Lists</code> table</li>
  </ul></li>
  </ol>
  
  <p>That's basically it. Pretty simple, but obviously there are nest queries within #4. I don't know if I should be creating one giant object in my queries and then outputting that? Or creating a bunch of different objects with arrays inside of them? Really kind of lost since this style of syntax is different than say PHP. Advice?</p>
  
  <p>Here is my non-database connected version:</p>
  
  <pre><code>app.get('/', function(req, res){
  
  var frontpageImages = [
          { caption:"Eggplant, Prosciutto, and Pesto Pressed Sandwiches.", file:"image01.jpg", position:"15%" },
          { caption:"Pico de Gallo", file:"image02.jpg", position:"75%" },
          { caption:"B.L.A.T Croque Madame", file:"image03.jpg", position:"20%" },
          { caption:"Double Oreo Brownie Cupcake", file:"image04.jpg", position:"80%" },
          { caption:"Baked Chicken Chimichangas with Monterey Jack Cheese Sauce", file:"image05.jpg", position:"20%" }
          ]
  
  var menu = [
          { divider:"Appetizers" },
          { name:"French Fries", picture:"menu-french-fries", subname:"$4.95" },
          { name:"Loaded Cheese Fries", picture:"menu-cheese-fries", subname:"$7.95" },
          { name:"Gaelic Chips", picture:"menu-gaelic-chips", subname:"$2.95" },
          { name:"Jalapeno Mac n' Cheese", picture:"menu-jalapeno-mac-n-cheese", subname:"$4.95" },
          { name:"Chicken Wings", picture:"menu-chicken-wings", subname:"$8.50" },
          { name:"Irish Nachos", picture:"menu-irish-nachos", subname:"$8.50" },
          { name:"Black &amp; Tan Onion Rings", picture:"menu-onion-rings", subname:"$6.95" },
          { name:"Mac's Quesadillas", picture:"menu-quesadillas", subname:"$8.50" },
          { name:"Banger Bites", picture:"menu-banger-bites", subname:"$7.95" },
          { divider:"Salads" },
          { name:"Caesar Salad", picture:"menu-caesar-salad", subname:"$6.50" },
          { name:"House Salad", picture:"menu-house-salad", subname:"$6.50" },
          { name:"Buffalo Chicken Salad (Grilled or Battered)", picture:"menu-buffalo-chicken-salad", subname:"$8.95" },
          { divider:"Sandwiches &amp;amp; Burgers" },
          { name:"Rueben", picture:"menu-reuben", subname:"$8.50" },
          { name:"Dublin Corned Beef", picture:"menu-corned-beef-sandwich", subname:"$8.50" },
          { name:"Philly Cheese Steak", picture:"menu-philly-cheese-steak", subname:"$8.50" },
          { name:"Grilled Chicken", picture:"menu-grilled-chicken-sandwich", subname:"$8.50" },
          { name:"Club Sandwich", picture:"menu-club-sandwich", subname:"$8.50" },
          { name:"Not-So-Irish Burger", picture:"menu-irish-burger", subname:"$9.95" },
          { name:"Dirty Burger", picture:"menu-dirty-burger", subname:"$7.95" },
          { name:"Aurora Burger", picture:"menu-aurora-burger", subname:"$10.95" },
          { name:"Bleu Cheese Burger", picture:"menu-bleu-cheese-burger", subname:"$11.95" },
          { name:"Additional Burger Toppings", picture:"menu-burger-toppings", subname:"$0.50" },
          { divider:"Irish Favorites &amp;amp; Entrees" },
          { name:"Beer Battered Fish N' Chips", picture:"menu-fish-and-chips", subname:"$11.50" },
          { name:"Bangers And Mash", picture:"menu-bangers-and-mash", subname:"$10.95" },
          { name:"Shepherd's Pie", picture:"menu-shepherds-pie", subname:"$10.95" },
          { divider:"Brunch" },
          { name:"Irish Breakfast", picture:"menu-irish-breakfast", subname:"$11.50" },
          { name:"American Breakfast", picture:"menu-american-breakfast", subname:"$11.50" },
          { name:"Irish Breakfast Roll", picture:"menu-irish-breakfast-roll", subname:"$8.95" },
          { name:"English Muffin, Scrambled Eggs, Cheddar and Irish Rasher", picture:"menu-irish-rasher", subname:"$7.50" },
          { name:"3 Egg Omelette", picture:"menu-omelette", subname:"$6.50" },
          { name:"Eggs Benedict", picture:"menu-eggs-benedict", subname:"$8.50" },
          { name:"3 Pancakes with Maple Syrup", picture:"menu-pancakes", subname:"$6.00" },
          { name:"Grilled Turkey and Swiss", picture:"menu-grilled-turkey-and-swiss", subname:"$7.00" }
          ];
  
  var drinks = [
          { name: "Bahama Bomb", desc: "Bacardi 151 Rum, Cruzan Coconut Rum, Creme de Banana, Pineapple juice, and Sprite.", subname: "$9.95" },
          { name: "Tropical Margarita", desc: "Grand Marnier, Cruzan Coconut Rum, Blue Curacao, sour mix, and orange juice. Garnished with lemon, lime, and cherry.", subname: "$10.95" },
          { name: "LOL[emonade]", desc: "Absolute Citron, Triple Sec, muddled lemon and simple syrup, sour mix, and Sprite.", subname: "$9.95" }
          ];
  
  var events = [
          { divider:"Upcoming Events" },
          { name: "Super Bowl Party", subname: "1/28" },
          { name: "Valentine's Singles Party", subname: "2/14" },
          { divider:"Weekly Events" },
          { name: "Hospitality Night", subname: "Monday" },
          { name: "Trivia Night", subname: "Tuesday" },
          { name: "Karaoke with Liam", subname: "Thursday" }
          ];
  
  res.render('index', {
      nav:[
          { name:"Home", title:"Clark's Bar and Grille", url:"home", icon:"home", module:"home", run:"startSlider", source:frontpageImages },
          { name:"Menu", url:"menu", icon:"cutlery", module:"list", source:menu },
          { name:"Drinks", url:"drinks", icon:"glass", module:"list", source:drinks },
          { name:"Events", url:"events", icon:"calendar", module:"list", source:events },
          { name:"Restaurant Info", title:"Restaurant Info", url:"business-info", icon:"info-circle", module:"business-info" },
          { name:"Instagram Feed", title:"Instagram", url:"instagram", icon:"instagram", module:"instagram", run:"startInstagram" },
          { name:"Like and Follow Us", title:"Social Media", url:"social-media", icon:"thumbs-up", module:"social-media-links" },
          { name:"Contact Clark's", title:"Contact Clark's", url:"contact", icon:"envelope", module:"contact" }
          ]
  });
  </code></pre>
  
  <p>});</p>
  
  <p>When the page renders now, I have the index.ejs loop the <code>nav</code> object and display each DIV (Home, Menu, Drinks, Events, etc). Each array within the <code>nav</code> object has a key called <code>source</code> which returns the objects for them listed above. The page renders perfectly, it's just not connected to a database. I would like to swap all that out with a DB connected version!</p>