Skip to content

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

Notifications You must be signed in to change notification settings

bonjs/caller-dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caller-dir Build Status

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 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

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published