Js file document on load is not working?

hi there, i am trying to load a simple client.js file from my html file and inside the client js contains something like this

$(function() {
const jsonfile = require(“jsonfile”);
const file = “./data/json/fund_tracking.json”;

console.log(“test”);
var jsonObj = jsonfile.readFile(file, function(err, obj) {
if (err) console.error(err);
console.dir(obj);
});

console.log(JSON.stringify(jsonObj));
});

just a simple on site load, put my data from json to obj and wanna load it to html. But with the console.log(“test”), i am not seeing that being print in the console which is i think is not loading in.

here is my url

Hey @intothefantasy,

Can you try this:

window.onload = function() {
 const jsonfile = require(“jsonfile”);
const file = “./data/json/fund_tracking.json”;

console.log(“test”);
var jsonObj = jsonfile.readFile(file, function(err, obj) {
if (err) console.error(err);
console.dir(obj);
});

console.log(JSON.stringify(jsonObj));
}

tested it and launch my site, no luck in printing the test on my console tho

i think i found out the issue,

this is due to the client side with the require issue

const jsonfile = require(“jsonfile”);

thanks Khalby786 for the help

this can only be invoke from nodejs