What is the standard method for writing JavaScript objects to a JSON file in Node.js?

Question

Grade: Education Subject: Support
What is the standard method for writing JavaScript objects to a JSON file in Node.js?
Asked by:
85 Viewed 85 Answers

Answer (85)

Best Answer
(192)
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.