Answers for "read write json nodejs"

1

write json file in node js

function writeJsonFile(file, content) {
  let jsonData = JSON.stringify(content)
  fs.writeFileSync(file, jsonData)
}
Posted by: Guest on June-07-2021
9

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));
Posted by: Guest on April-13-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language