node write to jason code example
Example 1: write json file nodejs
const fs = require('fs');
const path = require('path');
let student = {
name: 'Mike',
age: 23,
gender: 'Male',
department: 'English',
car: 'Honda'
};
fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
Example 2: write json file in node js
function writeJsonFile(file, content) {
let jsonData = JSON.stringify(content)
fs.writeFileSync(file, jsonData)
}