absdir

1.0.6 • Public • Published

absdir

Find the absolute directory path of a filename or a module object. No more excuses for __dirname.

Usage

from test/howto.js:

var moduleDir = require('absdir')(module);
equal(pathLib.join(moduleDir, 'howto.js'), module.filename);

API

This module exports one function:

absdir(pathOrModule[, prefixPath])

Without prefixPath, returns the absolute path to the parent directory of pathOrModule. An object with a string-type url property (e.g. your ES6 module's import.meta) is fine, too.

With prefixPath, returns a function that will resolve paths relative to pathOrModule's parent directory and the prefixPath (use . if you don't need a prefix).

 

Better than __dirname

  • Always gives an absolute path, so paths based on that won't crumble when your process changes its working directory.
  • Easily avoid those ugly __. (for JSLint#39)

 

License

ISC

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i absdir

      Weekly Downloads

      3

      Version

      1.0.6

      License

      ISC

      Unpacked Size

      4.49 kB

      Total Files

      4

      Last publish

      Collaborators

      • mk-pmb