Answers for "save json var to file nodejs"

15

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
2

nodejs manipulate file json write

//change the value in the in-memory object
content.val1 = 42;
//Serialize as JSON and Write it to a file
fs.writeFileSync(filename, JSON.stringify(content));
Posted by: Guest on December-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language