I'm trying to change a value within a config and then use that new value later?
// CONFIG.JSON
// BEFORE CHANGE
{
"value": "baz"
}
// AFTER CHANGE
{
"value": "foobar"
}
// MAIN JS ILE
const config = require('config.json')
function changeValue() {
config['value'] = "foobar"
var config_string = JSON.stringify(config, null, 4)
fs.writeFile(config_dir, config_string, (err) => {
if (err) {console.log("error", err)}
})
}
function useValue() {
console.log(config['value'])
// output will be "baz"
// fs.writeFile does not change the file data until the end of the whole script
// which is why I need help, how can I change a value and use it if ^^^
}