remicastaing
remicastaing

Reputation: 173

Path of the requiring script inside the required script

I have two scripts: the first requiring the second.

1st script main.js:

...
var a = require(second);
...

2d. script second.js

path = path/of/the/main/script

I want to get access to the path of the first script within the second script without passing it as argument. Is it a way to achieve it?

Upvotes: 0

Views: 48

Answers (1)

fakewaffle
fakewaffle

Reputation: 3081

module.parent.filename holds the file name of the calling script. See here for more information.

Upvotes: 1

Related Questions