1'use strict';
2
3const fs = require('fs');
4
5let student = {
6 name: 'Mike',
7 age: 23,
8 gender: 'Male',
9 department: 'English',
10 car: 'Honda'
11};
12
13let data = JSON.stringify(student, null, 2);
14
15fs.writeFile('student-3.json', data, (err) => {
16 if (err) throw err;
17 console.log('Data written to file');
18});
19
20console.log('This is after the write call');
21
1const fs = require('fs');
2const path = require('path');
3
4let student = {
5 name: 'Mike',
6 age: 23,
7 gender: 'Male',
8 department: 'English',
9 car: 'Honda'
10};
11
12fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
13