1const fs = require('fs');
2
3// create a JSON object
4const user = {
5 "id": 1,
6 "name": "John Doe",
7 "age": 22
8};
9
10// convert JSON object to string
11const data = JSON.stringify(user);
12
13// write JSON string to a file
14fs.writeFile('user.json', data, (err) => {
15 if (err) {
16 throw err;
17 }
18 console.log("JSON data is saved.");
19});
20