title: Use a node module from casperjs
body: <p>Is it possible to install a node module, installed via npm, and then <code>require</code> it from a casperjs script?</p>
  
  <p>(I see lots of posts and tools for running casper or phantom from inside node.js, but that is not what I'm trying to do.)</p>
  
  <p>The casperjs docs seem to say it is possible, but only show with hand-written toy modules that don't really do anything. The real-world module I'm trying to install is <code>imap</code>, but at this point I cannot get any module to work, even built-in ones like <code>net</code>. Simple example:</p>
  
  <pre class="lang-none prettyprint-override"><code>npm install imap
  echo "var test = require('imap');" &gt; test.js
  casperjs test.js
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre class="lang-none prettyprint-override"><code>CasperError: Can't find module imap
  
  /usr/local/src/casperjs/bin/bootstrap.js:263 in patchedRequire
  test.js:1
  </code></pre>
  
  <p>(I can see the imap module from <code>npm ls</code>, and I can use it fine from a node.js script.)</p>
  
  <p>Or alternatively with a built-in module:</p>
  
  <pre><code>echo "var test = require('net');" &gt; test.js
  casperjs test.js
  </code></pre>
  
  <p>Complains "Can't find module net"</p>
  
  <hr>
  
  <p>I have <code>npm --version</code> of 1.4.14 and <code>nodejs --version</code> of v0.10.29. Are either of those too old, I wonder? (Casper is 1.1.0-beta, and Phantom is 1.9.7, both of which are the latest versions.)</p>