title: node.js: How to include external .js from another server?
body: <p>I am trying to include .js files that are located on another server into my node.js program. Is this possible?</p>
  
  <p>I can´t use <code>require('./local_file.js')</code> and get something over the Internet like this: <code>require('http://www.server.com/path/file.js');</code></p>
  
  <p>I´ve tried to make a http.request and then use eval(), but the scope is all wrong and the functions inside the external file remain undefined:</p>
  
  <pre><code>var source_string = load_contents_via_http('http://www.server.com/folder/file.js');
  var source_string += '\n run_my_function();';
  eval(source_string);
  </code></pre>
  
  <p>Does anyone have any suggestions?</p>
  
  <p>Edit (Solution): 
  I solved my problem by repacking the essential parts into the script that runs on my local server, as mentioned by @zackehh. Then I used http.request to load and eval specific parts from the remote server when needed. Since the most important code was running on the server locally, the imported extra code was easier to add.</p>
  
  <p>Here is a example on how I solved the problem:</p>
  
  <pre><code>var EssentialObject = {};
  EssentialObject.ServerFunctions = {};
  EssentialObject.ServerFunctions.Init = function (){
    var external_code = load_contents_via_http('http://www.server.com/file.js');
    var eval_this = external_code.substr(
      external_code.indexOf('EssentialObject.Addons = {}'),
      external_code.indexOf('// End of EssentialObject.Addons')-external_code.indexOf('EssentialObject.Addons = {}')
    );
    eval ( eval_this );
    eval ( "EssentialObject.Addons.test=true; console.log('Eval Done')" ); // Check if it works
  };
  </code></pre>