index.ts590 chars24 linesExplanation:
fs module is imported to access file system functions.data object to be appended is defined.fs.readFile() function is used to read data.json file.fs.readFile():
if block checks for errors while reading the file.try block is used to parse the JSON string and add the data object to it.fs.writeFile() function is called to write the updated JSON string to the file.fs.writeFile(), if block checks for errors while writing the file.gistlibby LogSnag