How to load and save a JSON file in the server?


I'm trying to load and save a JSON file that sits on the same folder as server.js, from a sketch.ks. This is the folder structure

sketch/ node_modules/ journal.json server.js public/ index.html sketch.js style.css

I'm not sure if I should do this in the sketch.js...

loadJSON("path", gotData);

... but I'm not sure what the path would be. Or if I should first load the JSON in the server:

var fs = require('fs'); var data = fs.readFileSync('journal.json'); var journal = JSON.parse(data); console.log(journal);

and fetch the data from sketch.js.

Is there a tutorial or example that explains this? I've only been able to find Daniel Shiffman's videos but they only refer to loading a JSON file from a public API, where the path is very clear.

Thanks in advance!

Sign In or Register to comment.