I'm currently coding a webapp with Javascript and i wrote this:
const fs = require('fs')
function jsonReader(filepath, cb) {
fs.readFile(filepath, 'utf-8', (err, fileData) => {
if (err) {
return cb && cb(err);
}
try {
const Object = JSON.parse(fileData);
return cb && cb(null, Object);
} catch (err) {
return cb && cb(err)
}
})
}
This is just a function that parses the data from the json file. But the problem with the require is that the console always says: Uncaught ReferenceError: require is not defined. Can someone help me out there because I'm really new to Node js and also Javascript!