title: node.js index.html javascript function not defined
body: <p>I have an '<em>index.html</em>' page that references a javascript file of mine, '<em>bargraph1.js</em>', that is in the same directory as <em>index.html</em>.  In the html file, I call a function in that js page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
     &lt;head&gt;
       &lt;meta charset="utf-8"&gt;
       &lt;title&gt;D3 Test&lt;/title&gt;
  
       &lt;script type="text/javascript" src="d3.v4/d3.js"&gt;&lt;/script&gt;
       &lt;script type="text/javascript" src="bargraph1.js"&gt;&lt;/script&gt;
  
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h2&gt;BarGraph&lt;/h2&gt;
        &lt;script type="text/javascript"&gt;
           barGraph(null, null, null, 30);
        &lt;/script&gt;
  
    &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>The file <em>bargraph1.js</em> contains one function '<strong>barGraph()</strong>' that uses d3 to render a bar graph.</p>
  
  <p>If I open this file with 'file open' in my browser, it renders beautifully with no errors in the browser error console.</p>
  
  <p>HOWEVER, if I try to serve the page from a nodejs server, the bar graph does not appear and the console shows '<strong>barGraph not defined</strong>'.  The h2 header preceeding it does show up, though.  (Actually I don't think it can find anything in any of the referenced .js files when served by the server).  Here's the server code:</p>
  
  <pre><code>var app  = require ('express')();
  var http = require ('http').Server(app);
  var io   = require ('socket.io')(http);
  
  var pagePath = __dirname + '/index.html';
  console.log('sending page ' + pagePath + '\'');
  app.get ('/', function(req, res) { res.sendFile(pagePath); });
  
  io.on ('connection', function(socket) {
     console.log ('\nsocket.id ' + socket.id + ' connected');
  
     socket.on ('disconnect', function() {
        console.log ('\nsocket.id ' + socket.id + ' disconnected');
     });
  });
  
  //===================================================
  // set HTTP server to listen on port 3001
  //===================================================
  
  http.listen (3001, function() {
      console.log(' (3) http listening on *:3001 '); 
  });
  </code></pre>
  
  <p>SO - obviously there is something different about how things get resolved (paths?) in these two different ways to show the html page with javascript.  I have been using this same bargraph1.js file many times in files opened locally in the browser so I am sure there are no syntax errors in it.</p>
  
  <p>How can I get this file and the functions contained in it to work with a nodejs server?</p>
  
  <p>Thanks</p>