title: Drawing graphics on canvas in node-js/Express
body: <p>I want to draw a chart on canvas element. My Jade file contains following:</p>
  
  <pre><code>div
     canvas
  </code></pre>
  
  <p>In my index.js file in node.js web application, I tried the following:</p>
  
  <pre><code>var canvas = document.getElementById('canvas');
  var context = canvas.getContext('2d');
  context.beginPath();
  context.strokeStyle = "rgba(255, 0, 0, 1)";
  height = canvas.height;
  width = canvas.width;
  context.moveTo(0, 0);
  context.lineTo(width, height);
  context.lineWidth = 1;
  context.stroke();
  </code></pre>
  
  <p>However, it fails to recognize "document". My question is how do I obtain the reference to "canvas" in my .js file? Note that the actual chart would be more complex than the simple line drawing code shown above for brevity. The data for the chart is generated in index.js file at the server end. So the chart will be created on the server.  </p>