title: Binary file in npm package
body: <p>I try to create an npm package, which can be started as a command from shell. I have <code>package.json</code></p>
  
  <pre><code>{
    "name": "myapp",
    "version": "0.0.6",
    "dependencies": {
      "async": "",
      "watch": "",
      "node-promise": "",
      "rmdir": "",
      "should": "",
      "websocket": ""
    },
    "bin": "myapp"
  }
  </code></pre>
  
  <p>and <code>myapp</code></p>
  
  <pre><code>#!/bin/bash
  
  path=`dirname "$0"`
  file="/myapp.js"
  
  node $path$file $1 &amp;
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>module.js:340
      throw err;
            ^
  Error: Cannot find module '/usr/local/bin/myapp.js'
      at Function.Module._resolveFilename (module.js:338:15)
      at Function.Module._load (module.js:280:25)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:902:3
  </code></pre>
  
  <p>The problem is that myapp.js is in another directory. How can I get this directory name from my script? Or maybe there is better way to do this?</p>