In a naive implementation of mymodule, I did the following
const file = fs.readFileSync('./node_modules/dependent_module/file.txt')
However, when I include mymodule in project, the file read no longer works since the location of dependent_module has moved.
How can I read a file from a node module, such that I don't have to worry about where that node module is located?
Use require.resolve('module') then include that in the file path of the file you'd like to read
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With