I am new but I have a function to write into a file JSON. But I want to write into a file. But require is not defined. So I use requirejs to be able to use fs so I can write file from a javascript function which would call that function. But I cannot understand how to "import" fs from node with requirejs, and even if it's possible to use fs with requirejs. Please help me if you can. Thank you a lot.
I tried to configure like on the site of requireJs for module of Node like that:
var requirejs = require('requirejs');
requirejs.config({
nodeRequire : require
});
requirejs(['fs'],
function (fs)
{
});
At the beginning, I have put my function into the function "function (fs) " but no result...
Here is my function js I want to use. She write into a json file after clicking on a button on BabylonJS for a virtual tour, a scene construction.
const fs = require('fs');
var obj = {
story: []
}
obj.story.push(
{"name": "infoHotspot",
"type": "info",
"position": (0,1,1)
})
var json = JSON.stringify(obj);
fs.writeFile('myjsonfile.json', json, 'utf8', function (err) {
if (err) console.error(err)
});