title: Return value from NodeJS Query, and store the results in a object variable to use on every page
body: <p>So I'm trying to make a simple page handler for a website (My First NodeJS Project) and struggling to get my head around how to get a MySQL Query to run each time and store the returned data in a variable to be used throughout the application. (I should note I'm using ExpressJS)</p>
  
  <p>Currently in my app.js file I have the following, which seems to be doing it's job at executing for each page load</p>
  
  <pre><code>app.use(pageHandler);
  </code></pre>
  
  <p>Inside the pageHandler module, I have the following which queries the database based on the URL of the page.</p>
  
  <pre><code>var pageHandler= app.use(function (req, res, next) {
      console.log('Trying to find details for page: ' + url.parse(req.url).pathname);
      db.query("SELECT * FROM `pages` WHERE page_url = ?", [url.parse(req.url).pathname], function(err, result) {
          res.send(result);
      });
  });
  
  module.exports = pageHandler;
  </code></pre>
  
  <p>This does infact print, the successful results on the page, but I'm wanting to store them in a variable wihch I can use throughout the application to get for example the title of the page and whatnot. Currently returns the following from database.</p>
  
  <pre><code>[  
     {  
        "id":1,
        "page_url":"/",
        "title":"Home",
        "meta_title":"First Node Project",
        "meta_description":"Placeholder",
        "meta_keywords":"nodejs, keywords, etc",
        "parent_id":0,
        "position":0,
        "template":"home",
        "content":"Lipsum..."
     }
  ]
  </code></pre>