title: How to call a node function from client-side javascript? (HTML)
body: <p>I have a node app called <code>index.js</code> that runs express. A while ago I decided to merge a website template and my node app together and everything works fine up to here. I am able to load other paths into the node app (<code>index.js</code>) by using the below code.</p>
  
  <pre><code>var express = require('express');
  var app = express();
  app.use('/assets', express.static(path.join(__dirname, '/assets')));
  app.use(express.static(path.join(__dirname, '/')));
  </code></pre>
  
  <p>Now, I am able to serve different html pages using express, which means my app is able to access the <code>assets</code> folder and the content inside the folder.</p>
  
  <p>Now, the assets folder contains other folders called js, css and... The HTML template is loading all it's javascript codes from the <code>js</code> folder in <code>assets</code>. Note the javascript codes are not written in the HTML file. Here's an example of how a script is triggered in my HTML code: </p>
  
  <pre><code>&lt;script src="../../assets/js/test.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              test.theFunction();
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>And here's the javascript code in the following directory:</p>
  
  <pre><code>// assets/js/test.js
  test = {
    theFunction: function() {
      res.send("finally...");
      console.log("sup?");
    }
  }
  </code></pre>
  
  <p>I am trying to call the following function inside <code>index.js</code> from <code>test.js</code>:</p>
  
  <pre><code>// /index.js
  app.get("/hey", function(req, res) {
    res.send("wassaaa!!");
  });
  </code></pre>
  
  <p>So far, I've tried the following code, but it doesn't call the function:</p>
  
  <pre><code>  $.get('/hey').success(function(response) {
      $scope.final = response;
      console.log(response);
    });
  </code></pre>
  
  <p>I've also tried <code>module.exports</code> in <code>index.js</code>, but when I require it in <code>test.js</code> I get an error saying that I can't require stuff on the client side.</p>
  
  <p>I've also looked at some examples regarding require.js, but the examples mostly explain how to load require.js in the HTML file rather than directly in a js file.</p>
  
  <p>To sum it up, here's what I want to happen: HTML file triggers the functions in <code>test.js</code>, then <code>test.js</code> gets some data from <code>index.js</code> and passes it to the HTML file again... I am trying to avoid writing the javascript codes in the HTML file.</p>
  
  <p>I'm also open to suggestions if anyone knows how to achieve what I am trying to do in an easier way. Thanks in advance...</p>