caller-dir
caller-dir
A tool which could get the dirpath of a function method’s caller
1 | 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 it’s 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
1 | const getCallerDir = require('caller-dir'); |
file B /src/b.js
1 | var A = require('./module/a'); |
output: /src