I have object in my JavaScript file and empty json file. How can I just write this object to the json file? I tried "require" or "import" but get errors all the time. What is generally correct way to write info to json file?
function readInput() {
fetch("./input.json")
.then((response) => response.json())
.then((data) => {
// do some work with data
});
}
now I want to write data to new json file. When I do this as in tutorials
const fs = require('fs')
I get "require is not defined" and it suggests me to conver require to
import { writeFile } from 'fs';
now I have error "Cannot use import statement outside a module"
Cannot understand what is needed to write to json file