Walrus
0
Q:

read json file nodejs

const fs = require('fs');
const path = require('path');

let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
7
// Use the Fetch API & ES6
fetch('data.json')
  .then(response => response.json())
  .then(data => {
  	// Do something with your data
  	console.log(data);
  });
8
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));
6

New to Communities?

Join the community