I am trying to make an online game. It is not fast-paced, so I only need a json file. I am very new to node.js and don't really know much about it.
I have tried using this: https://stackabuse.com/reading-and-writing-json-files-with-node-js/ and I understand how to read and write to it with the command line. How can I run a node js file from a javascript event like OnClick?
The node js:
//this code is mostly stolen from the site I linked to.
'use strict';
const fs = require('fs');
let newdata = {"newdata": "this is new!"}
let data = JSON.stringify(newdata);
fs.writeFileSync('data.json', data);
The json:
{
"test": "hello world"
}
The html:
<input type="button" value="Click Me!" onclick="
//run the node js file!!!
">
I have no idea what I can do to run the file.