required-from
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

required-from

CircleCI NPM Downloads node License MIT

Get absolute path to the module that required your module

Usage

Get Absolute Path of Parent Module

// project root
 
  ├── index.js
  ├── foo.js
  ├── bar.js
  └── baz.js
 
// index.js (entry point of app)
 
const foo = require('./foo')
 
// foo.js
 
const bar = require('./bar');
 
// bar.js
 
const requiredFrom = require('required-from');
 
const requireDirectory = requiredFrom();
 
console.log(requiredDirectory); // /absolute/path/to/foo.js
 

Note: It will throw an error if you try to call it from a module that is not required by a parent module during runtime.

License

MIT © Nivrith Mandayam Gomatam

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.0
    11
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.2.0
    11
  • 1.1.0
    0
  • 1.0.3
    0
  • 1.0.2
    0
  • 1.0.1
    0

Package Sidebar

Install

npm i required-from

Weekly Downloads

11

Version

1.2.0

License

MIT

Unpacked Size

80.5 kB

Total Files

20

Last publish

Collaborators

  • nivrith