I try to create an npm package, which can be started as a command from shell. I have package.json
{
  "name": "myapp",
  "version": "0.0.6",
  "dependencies": {
    "async": "",
    "watch": "",
    "node-promise": "",
    "rmdir": "",
    "should": "",
    "websocket": ""
  },
  "bin": "myapp"
}
and myapp
#!/bin/bash
path=`dirname "$0"`
file="/myapp.js"
node $path$file $1 &
But I get an error:
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
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?
 
     
    