title: How to send Node.js server data to Javascript client?
body: <p>I am trying to send server data to my javascript client and then output it in html(jade). </p>
  
  <p><strong>Problems</strong>
  <br>1. My Js Client &amp; Html variables (publicKey, name, artist, picture, id) are "undefined"
  <br>
  2. Not clear on "try" or "catch" conditionals mean (maybe this is affecting something)</p>
  
  <p><strong>My Research</strong>
  <br> <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest</a>
  <br> <a href="https://stackoverflow.com/questions/6011984/basic-ajax-send-receive-with-node-js">Basic Ajax send/receive with node.js</a>
  <br> </p>
  
  <p>Is the problem likely in my server code, Javscript client, or Jade?</p>
  
  <p><strong>Node.js server</strong></p>
  
  <pre><code>app.get('/user/:id', function (req, res) {
    if (!req.user)
      res.send(err);
    if(req.user) {
      try {
        var id = req.params.id;
        var dbUser = req.user;
  
        res.send({
          'publicKey': dbUser.publicKey,
          'name': dbUser.name,
          'artist': dbUser.artist,
          'picture': dbUser.picture,
          'id':  dbUser.id
        });
  
      } catch (e) {
        res.send({'status': 404});
      }
    } else {
      res.send({'status': 403});
    }
  
  });
  </code></pre>
  
  <p><strong>Js Client</strong></p>
  
  <pre><code>  var keysCache = {};
    var xhr = new XMLHttpRequest();
    xhr.open('GET', '/user/' + message.userid, true);
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4) {
        var res = JSON.parse(xhr.responseText);
  
        keysCache[message.userid] = {
          'publicKey': res.publicKey,
          'name': res.name,
          'artist': res.artist,
          'picture': res.picture,
          'id': res.id
        }
        console.log(res.name);
        displayOutput(message);
      }
    };
    xhr.send(null); 
  </code></pre>
  
  <p><strong>Jade</strong></p>
  
  <pre><code> #chat
    (...)
    script.
     window.user = {id:"#{user.id}", name: "#{user.artist}", picture: "#{user.picture}", gtoken: "#{user.gtoken}", eccKey: "#{user.eccKey}"};
    script(src='/javascripts/client.js')
  </code></pre>