I have a NodeJS module that does a lot of work on the filesystem in a particular directory. I would like all filesystem operations inside the module to be done relative to that directory - (let's call it /home/me/data
).
I realise I could change the current working directory with process.chdir("/home/me/data");
but that would mess up the working directory of any other modules that are using my module.
Is there a way that a child module can have a different working directory than it's parent?
I don't want to have to pass a variable through to every sub-module to be appended to the filepath of fs.readFile(filepath);
calls.
Are there any elegant ways of achieving this?
P.s. child process spawning / forking is not appropriate here.