Question
What is the standard method for writing JavaScript objects to a JSON file in Node.js?
Asked by: USER1517
85 Viewed
85 Answers
Answer (85)
To write a JavaScript object to a JSON file, you first convert the object to a JSON string using `JSON.stringify()`. Then, you use `fs.writeFileSync` to write this string to your desired file.