title: NodeJS/Browser Cross-Development
body: <p>I'm working on a library that targets both browsers and NodeJS applications. Modules use AMD convention which is theorically flexible enough to map pretty much any situation today. Source files are then to be converted with tools to be distributed for different platforms - again browsers and NodeJS.
  By the way, there's a wonderful tool called <a href="http://urequire.org/" rel="nofollow">uRequire</a> to help with that but I'm still not sure what my best option is, so I'm asking here for relevant experience.</p>
  
  <p>Here are the files hierarchy I have:</p>
  
  <pre><code>- bower_components/
      - eventemitter2/ ...
      - lodash/ ...
  
  - source/
      - library/
          - lodash.js -&gt; ../../bower_components/lodash/dist/lodash.js
          - EventEmitter.js -&gt; ../../bower_components/eventemitter2/lib/eventemitter2.js
  
      - Observable.js:
  
          define(["lodash", "EventEmitter"], function(Utility, EventEmitter) {
              function Observable(options) { ... };
  
              return Observable;
          });
  </code></pre>
  
  <p>At the end, the big difference between browser and NodeJS sides is:</p>
  
  <ul>
  <li>Browser-side: <code>EventEmitter</code> implementation simply is the <code>eventemitter2</code> browser module that is configured to be "library/EventEmitter";</li>
  <li>NodeJS-side: <code>EventEmitter</code> is gotten from <code>require("events").EventEmitter</code>, with <code>events</code> being a native package, not a local file or module;</li>
  </ul>
  
  <p>So, my question is: how can I have that <code>Observable</code> object work with NodeJS without massive tinkering? What I'm not sure about how I can make the <code>EventEmitter</code> implementation available to my module since it is not a local module (as such I cannot write any paths mapping) and moreover it is not directly the module itself we'll use but the "EventEmitter" property of it...</p>
  
  <p>Any help/thinking would be appreciated. I believe that many have run in similar situations and I'd be curious to know what they have to say!</p>