Find the absolute directory path of a filename or a module object. No more excuses for __dirname.
from test/howto.js:
var moduleDir = require('absdir')(module);
equal(pathLib.join(moduleDir, 'howto.js'), module.filename);
This module exports one function:
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).
- 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)
ISC