1.0.4 • Published 5 years ago

caller-dir v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

caller-dir Build Status npm.io npm.io

A tool which could get the dirpath of a function method's caller

npm install caller-dir

Usually, if you want to get the current path, you can use __dirname in Nodejs, if you want to get the caller's dirpath, you can call the function with a parameter which is __dirname, but is not graceful.

Now you can use this little tool caller-dir to get the caller's dirpath gracefully.

eg. file A /src/module/a.js

const getCallerDir = require('caller-dir');

function A() {
	console.log(getCallerDir());
}
module.exports = A;

file B /src/b.js

var A = require('./module/a');
A();

output: /src

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago