I am trying to write a JSON file and for some reason fs.writeFile just won’t create and write the string in the file. The function described is being called by an HTML button :
<button type="button" onclick="writeJson ();">Write</button>
I press the button and nothing happens. I had error/success outputs in the function, but took them out in case they were causing the function to fail.
I am 99% sure it’s my syntax causing it, but I can’t seem to see where.
function writeJson () {
const fs = require('node:fs');
const stri= "test";
fs.writeFile('Test.json', stri, err => {
if (err) {
} else {
}
});
}