title: Creating npm package for both browser and node
body: <p>I'm trying to create an npm package that could be used by web apps or other node modules.</p>
  
  <p>If I were to only support browsers, I would just assign to window <code>window.myExport = myExport;</code> (unless there's a more modern way I'm not aware of?).</p>
  
  <p>If I were to only support node modules, I would just use export, <code>module.exports = myExport;</code> (again, if there's a better way I'm not aware of, please let me know).</p>
  
  <p>But I want to support both. Currently, what I'm doing is </p>
  
  <pre><code>var window, module;
  if (window)
      window.myExport = myExport;
  if (module)
      module.exports = myExport;
  </code></pre>
  
  <p>This looks very ugly, but works so far.
  What's a better approach?
  This is very lightweight node module, so I don't want to bring in some builder like webpack or something unless un-avoidable. I am already using babel though to create an es5 compatible version of my code, so if babel can solve this issue for me, that would work.</p>