title: Node js require code instead of file
body: <p>I am trying to setup an interface, where I can write one js file that can be used on the server (nodejs) and on the client (javascript).</p>
  
  <p>An example file would be a Vector object, that I would like to use on both the client and the server, as I am creating a multiplayer game.</p>
  
  <p>In node.js, I know that you can use the following syntax to require source files...</p>
  
  <pre><code>var Vector = require('./vector');
  </code></pre>
  
  <p>Then you can access its <code>module.exports</code> by typing in <code>Vector</code>.</p>
  
  <p>The problem here is that for the server I need an extra bit of code at the end of the file...</p>
  
  <pre><code>module.exports = Vector;
  </code></pre>
  
  <p>... which is not necessary on the client.</p>
  
  <p>Is it possible to maybe require source code, something like the following?</p>
  
  <pre><code>var data = (...) // get data from vector.js file
  var Vector = require_code(data + 'module.exports = Vector');
  </code></pre>
  
  <p>If not, there might be another way of doing what I am trying to accomplish.</p>
  
  <p>That might sound a little confusing, but help is greatly appreciated!</p>
  
  <p>Thanks in advance,</p>
  
  <p>David.</p>