# absdir

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

Latest version **1.0.6** (published 2018-06-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install absdir
pnpm add absdir
yarn add absdir
bun add absdir
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-06-02 |
| First published | 2016-08-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | M.K. |
| Maintainers | mk-pmb |
| Keywords | absolute path, absdirname, __absdirname |

## Links

- npm: https://www.npmjs.com/package/absdir
- Repository: https://github.com/mk-pmb/absdir-node
- Homepage: https://github.com/mk-pmb/absdir-node#readme
- Issues: https://github.com/mk-pmb/absdir-node/issues
- npm.io page: https://npm.io/package/absdir

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-06-02
- 1.0.5 — 2017-11-08
- 1.0.2 — 2017-07-01
- 1.0.1 — 2016-08-03
- 1.0.0 — 2016-08-03

## README

<!--#echo json="package.json" key="name" underline="=" -->
absdir
======
<!--/#echo -->

<!--#echo json="package.json" key="description" -->
Find the absolute directory path of a filename or a module object. No more
excuses for __dirname.
<!--/#echo -->

Usage
-----

from [test/howto.js](test/howto.js):

<!--#include file="test/howto.js" start="  //#u" stop="  //#r"
  outdent="  " code="javascript" -->
<!--#verbatim lncnt="4" -->
```javascript
var moduleDir = require('absdir')(module);
equal(pathLib.join(moduleDir, 'howto.js'), module.filename);
```
<!--/include-->



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`][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).



<!--#toc stop="scan" -->


&nbsp;

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](https://github.com/douglascrockford/JSLint/issues/39))




&nbsp;

  [import-meta]: https://github.com/tc39/proposal-import-meta

License
-------
<!--#echo json="package.json" key=".license" -->
ISC
<!--/#echo -->

---
_Source: https://npm.io/package/absdir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
