title: Error: Cannot find module 'd3'
body: <p>I'm trying to run a node script (<a href="https://github.com/trifacta/vega/wiki/Headless-Mode" rel="nofollow">vg2svg</a>), but get this error:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Error: Cannot find module 'd3'
      at Function.Module._resolveFilename (module.js:336:15)
      at Function.Module._load (module.js:278:25)
      at Module.require (module.js:365:17)
      at require (module.js:384:17)
      at Object.&lt;anonymous&gt; (/Users/my_user/repos/vega/index.js:10:6)
      at Module._compile (module.js:460:26)
      at Object.Module._extensions..js (module.js:478:10)
      at Module.load (module.js:355:32)
      at Function.Module._load (module.js:310:12)
      at Module.require (module.js:365:17)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I've installed nodejs and npm with macports, and d3 with <code>npm install d3</code>, but d3 doesn't seem to be recognized.</p>
  
  <p>When I run node from the macports dir (<code>/opt/local/bin/</code>) and do <code>require("d3")</code>  there's some sensible output, but when I <code>cd</code> to a different dir I get that <code>Cannot find module</code> error again.</p>
  
  <p>I've also tried a few variations on <code>export NODE_PATH=.:/opt/local/bin/:/Users/my_user/repos/vega/</code> but that didn't seem to help either.</p>
  
  <p>Any ideas?</p>