Node JS
Fetch JSON File
How to fetch JSON file data using Node JS
By Geekboots
8/18/2023
0 views
fetch-json-using-nodejs.jsJavaScript
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 }
NodeJSJavaScriptFetch DataJSON