Skip to content

Instantly share code, notes, and snippets.

@kulcsarrudolf
Created June 14, 2022 13:45
Show Gist options
  • Select an option

  • Save kulcsarrudolf/f76030ae308a242a2e1c9dfb97f10d5b to your computer and use it in GitHub Desktop.

Select an option

Save kulcsarrudolf/f76030ae308a242a2e1c9dfb97f10d5b to your computer and use it in GitHub Desktop.
writeObjectToJson.js
const fs = require("fs");
var Buffer = require("buffer/").Buffer;
const objectToJsonFile = async (targetDirectory, fileName, object) => {
const objectJSON = JSON.stringify(object);
const file = `${targetDirectory}/${fileName}.json`;
try {
const data = new Uint8Array(Buffer.from(objectJSON));
await fs.promises.writeFile(file, data);
} catch (err) {
console.error(err);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment