2

If I have a file running.js that includes another file dependency.js, what code in dependency.js will return the name of the including file running.js?

If I do path.basename(__filename) within dependency.js it returns 'dependency.js' not 'running.js'.

user779159
  • 9,034
  • 14
  • 59
  • 89
  • https://stackoverflow.com/questions/31643041/how-can-i-detect-the-entry-file-in-node-js don't want to flag as dupe because I'm not 100% this is what you're looking for, but `require.main.filename` seems to be what you're after – N.J.Dawson Nov 05 '17 at 09:01
  • Possible duplicate https://stackoverflow.com/a/32001075/3284355 – Molda Nov 05 '17 at 09:03
  • That returns the test runner that starts everything up. I need the file that directly includes the current one. – user779159 Nov 05 '17 at 09:04
  • Another possible duplicate https://stackoverflow.com/questions/13227489/how-can-one-get-the-file-path-of-the-caller-function-in-node-js. The far simpler method would be to pass the caller filename as an argument to the module. – John Nov 05 '17 at 10:04

0 Answers0