title: Suggestions for dealing with `exports` in node.js
body: <p><strong>Theory:</strong></p>
  
  <p>One of the things that appeals to me about node.js is using it as a command line tool. </p>
  
  <p>In theory, I can write libraries in Javascript and place them in my <code>~/.node_libraries</code> directory, and then then I can reuse those libraries. </p>
  
  <p>So for instance, I have a text.js in <code>~/.node_libraries</code>, and it has a bunch of text-related functions I use over and over (<code>depunctuate()</code>, <code>tokenize_text()</code>, things like that). </p>
  
  <p>The beauty of this is that I could use the same <code>text.js</code> file with my command-line scripts and server side. Right now I'm doing all that text processing stuff with Python, but I'd like to just stick to one language.</p>
  
  <p><strong>Practice:</strong></p>
  
  <p>AFAICT, in order to create a node.js module, I have to attach everything that I want to be available to <code>exports</code> or <code>this</code>. I.e., in <code>text.js</code>, I have to do:</p>
  
  <pre><code>exports.depunctuate = depunctuate
  </code></pre>
  
  <p>or</p>
  
  <pre><code>this.depunctuate = depunctuate
  </code></pre>
  
  <p>If I use <code>exports</code>, I have problems with using the library server-side à la:</p>
  
  <pre><code>&lt;script src=text.js&gt;&lt;/script&gt;
  </code></pre>
  
  <p>because then I get <strong>exports is not defined</strong> errors.</p>
  
  <p>If I use <code>this</code>, I avoid the error, but everything I export ends up getting attached to the window object.</p>
  
  <p>Is there some way I can set up these libraries that avoid both of these problems? For instance, is there some way I can wrap the exporting of <code>exports</code> so that the var will be apparent to node, but not when it's used in a plain Javascript file on a server?</p>