title: Determine command line working directory when running node bin script
body: <p>I am creating a node command line interface. It is installed globally and uses a bin file to execute.</p>
  
  <p>I plan to have a command window open at the root directory of the files I am working on and then just run the command however I have been unable to determine the current working directory as <code>process.cwd()</code> is returning the directory of the node package. I initially assumed that since the code is being executed using a batch file as a wrapper (that is how bin files can execute without node at the beginning) then it is impossible but coffee-script manages to do it. I took a look at the coffee-script source but couldn't follow it (not experienced enough).</p>
  
  <p>To test it for yourself create a package with this package.json file:</p>
  
  <pre><code>{
    "name": "test-package",
    "version": "1.0.0",
    "bin": {
      "test-package":  "./bin/test-package"
    },
    "main": "/lib/test"
  }
  </code></pre>
  
  <p>this test-package file in bin:</p>
  
  <pre><code>#!/usr/bin/env node
  
  var path = require('path');
  var fs   = require('fs');
  var lib  = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
  
  require(lib + '/test');
  </code></pre>
  
  <p>Could anyone shed some light onto this.</p>
  
  <p>and then try and get the command line directory inside lib/test.</p>