So let's say I have a .js file which exposes a function, which I want to be able to import in many other files. The function in this file needs access to some data stored in a certain file ( take .txt for this example) and I'm using the relative address to read and write to this text file.
Now the problem comes when I import this module into other files in different directories, the relative paths won't be valid but I don't know how I can change this? I'm sure there's a simple way to do this but I can't figure it out at all.
file 1
relative path = '../../file.txt'
function foo(){
fs.readFile(relativePath)
}
module.exports = {foo}
file 2
const {foo} = require('foo')
foo();