1👍
You can use the fs module to read and write to a file
var fs = require('fs');
var jsonfile = fs.readFileSync('the/path');
//if you want to write to the file I gave you a link that shows you the way
For more information about the fs module you can check File System | Node.js v12.6.0 Documentation.
You may need to pass by JSON.stringify and JSON.parse to save your object as a string in the file and to parse the string back to an object while reading the file.
Another manner that you may consider is lightweight javascript databases such as IndexedDB which is an embedded database in the browser side, or other databases such as neDB if you want to persist data especially with an electron app.
- [Chartjs]-Can we draw a Line Chart with both solid and dotted line in it?
- [Chartjs]-Chart Js Change Label orientation on x-Axis for Line Charts
0👍
Have many way to use with your wish
var data = {"a" : "b", "c" : "d"};
then
<script src="data.js" ></script>
or
var json = require('./data.json');
or
$.getJSON("data.json", function(json) {
console.log(json);
});
Good luck!
- [Chartjs]-YAxes not working with min max option
- [Chartjs]-Pie chart is not getting rendered in ChartJS
Source:stackexchange.com