In my JSON data file called total.json
, I store information for a chatbot.
{ "guilds": 3, "users": 21 }
Within my index.tsx
file, I want to display this data on the webpage, so I attempt the following:
import fs from 'fs';
function displayStats() {
const botStats = JSON.parse(fs.readFileSync(`../util/total.json`, { encoding: 'utf8' }));
const usersCount = botStats.users;
console.log(usersCount);
return usersCount;
}
Although the function correctly outputs the number (21) in the terminal, an error is encountered when trying to display it on the page:
TypeError: fs__WEBPACK_IMPORTED_MODULE_6___default(...).readFileSync is not a function