I have a JSON file about 300MB in size and I'm trying to read it but it's not working.
How can I read a large JSON file? If anyone can guide me with a small piece of code then it would be great.
I have already tried fs.readFile but no luck, it's working fine for smaller files but not for large ones.
Below is the code I have tried so far:
app.get('/getData', function (req, res) {
fs.readFile('./uploads/test.json', function (err, data) {
if (err) throw err
var jsonData = data;
var jsonParsed = JSON.parse(jsonData);
res.json(jsonParsed);
});
});
if (err) throw errshould log. And, you can put atry/catchwith logging in thecatcharoundJSON.parse(). You should at least start by logging possible errors in this code. This takes some elemental debugging on your part before any of us could help you. You should do that before you come here and then tell us what you found.