The data stored is in data.js file (not JSON) and it is an array of objects. As an example,
[
{"id":"u4cse101", "name":"supriya","batch":"b"},
{"id":"u4cse102", "name":"rahul", "batch":"a"},
{"id":"u4cse345", "name":"ahalya", "batch":"a"}
]
I tried many methods, but couldn't achieve. Your help will be appreciated.
UPDATE:
One solution found is have the following in data.js file
JOURNAL = [
{"x":"y"},
{"a":"a"}
];
if (typeof module != "undefined" && module.exports)
module.exports = JOURNAL;
and use the variable JOURNAL in another javascript file directly using require('./data.js'). But I am getting error:
if (typeof module != "undefined" && module.exports)
^^
SyntaxError: Unexpected token if
var fs = require('fs'); var array = JSON.parse(fs.readFileSync('./data.js', 'utf8'));data.json, not indata.js- the latter should be a JavaScript file, which JSON only technically is.