title: How to get current path of the file that run the script in nodejs
body: <p>So I have node modules that can be require for Internationalization.</p>
  
  <p>I'm trying to get the current path of the file that run my node module inside the nodule module.</p>
  
  <p>Use case #1:</p>
  
  <p>Inside <code>~/yourProject/node_modules/i18n.js</code></p>
  
  <pre><code>var current_path_to_locales_dir = path.join(__dirname, "locale");
  </code></pre>
  
  <p>And the path of the server is:</p>
  
  <pre><code>~/YourUserName/yourProject/app.js
  </code></pre>
  
  <p>Doing <code>var i18n = require("i18n");</code></p>
  
  <p>And trying to get the path it will return</p>
  
  <pre><code>/User/YourUserName/yourProject/node_modules/locale
  </code></pre>
  
  <p>Which is correct but I'm expecting it to look for</p>
  
  <pre><code>/User/YourUserName/yourProject/locale
  </code></pre>
  
  <p>Use case #2:</p>
  
  <p>Inside <code>~/i18nProject/i18n.js</code></p>
  
  <pre><code>var current_path_to_locales_dir = path.join(__dirname, "locale");
  </code></pre>
  
  <p>If I have a sample app in the <code>~/i18nProject/sample</code> and doing <code>var i18n = require("../i18n");</code></p>
  
  <p>The <code>locale</code> directory this time will be </p>
  
  <pre><code>/User/YourUserName/i18nProject/locale
  </code></pre>
  
  <p>Again the above is correct but I would expect it to be </p>
  
  <pre><code>/User/i18nProject/sample/locale/
  </code></pre>
  
  <p>Now I'm wondering if there is a way that I can get the path of the current running script?</p>