Fri Aug 18 2023
Fetch JSON File
Node JS100 views
File Name: fetch-json-using-nodejs.js
const fs = require('fs');
const getUsers = async () => {
try {
const data = fs.readFileSync('users.json', 'utf-8');
const jsonData = JSON.parse(data);
jsonData.map(usr => {
console.log('Id:', usr.id);
console.log('First Name:', usr.fstName);
console.log('Last Name:', usr.lstName);
console.log('Email:', usr.email);
})
} catch (err) {
console.error(err);
}
}
module.exports = { getUsers }
Author:Geekboots