Things work fine when I make a standalone project with two files, one called helperFuncs.js and the other called index.js, where helperfuncs.js has
function stringOfZeros(numZeros) {
//takes in a number and outputs a string with that many zeros;
...
}
module.exports = {
stringOfZeros: stringOfZeros,
}
and index.js has
const helperFuncs = require("./helperFuncs.js");
const stringOfZeros=helperFuncs.stringOfZeros;
let myZeroString = stringOfZeros(17);
console.log(myZeroString);
This works even with no package.json file in the project.
However, if I do the same thing where I create an identical helperFuncs.js file in a small HTML project that has an index.html page and a script.js file on the same level in the directory, and I set the above lines of code from the index.js file into the script.js file where the lines execute inside a window event load listener that otherwise works, I get this error:
TypeError: stringOfZeros is not a function
What am I doing wrong? Does the fact that it's inside a script file somehow require me to use "import" instead of require, or make it mandatory to make a package.json file where otherwise it was optional?
module.exportsis not valid. That's for node.js environments.