So, i have no idea about what I should type to get answers to those questions, I will explain my case here. I have a program, which is reading a JSON file that is being modified. The thing is, I am loading the file like the following.
const foo = require('./foo.json')
I would like to know how I could reload the file every time the constant is called so I am getting modifications in the file. I tried to use the following to do it :
const foo = JSON.parse(fs.readFileSync(fooPath))
But it doesn't look like what I want.
Seems like you are trying to reopen the json expecting it to have modified values.
Node.js uses cache on requires, so you would need to clear the cached require
delete require.cache[require.resolve('./foo.json')]
and then require the json again.
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