Imagine a directory structure like this:
module
index.js
project
main.js
file.yaml
Imagine further that inside the module/index.js
file, there is this code:
const fs = require('fs');
exports.test = function() {
// How should I *dynamically* reference the caller's app root directory?
console.log(fs.readFileSync('file.yaml', 'utf8'));
}
Inside the project/main.js
file, there is this code:
const x = require('./module');
x.test();
And inside the project/file.yaml
file, there is this code:
foo: bar
I want x.test();
to output the contents of project/file.yaml
, somehow dynamically referencing the caller's root directory.