Socket
Book a DemoInstallSign in
Socket

absdir

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

absdir

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

1.0.6
latest
Source
npmnpm
Version published
Weekly downloads
10
233.33%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

absolute path

FAQs

Package last updated on 02 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.