Basic questions on export/import



I am coming from a Java coding background, and am having trouble wrapping my head around Javascript’s more dynamic nature, especially when it comes to spreading code amongst files to modularize it. The books that I am reading are conflicting with what I am seeing, what is working, hence the confusion.

Some sources say that this will work:
import { item, item, item} from “/path/to/file.js”;

But when trying to use this structure in Electron, no go. So, I have started restructuring. I am now using in main.js:
const utilities = require(path.resolve(‘folder/utilities’));

The utilities.js file defines a single function (for now) that uses the following structure:
let myFunction = function (filepath) { … };

module.exports = myFunction();

Further down in my code in main.js, I want to call myFunction from utilities.js and pass a parameter.

I am getting the following error:
Uncaught ReferenceError: myFunction is not defined

Can someone please point out where, in this mixing and matching styles and usages, I am going wrong? I cannot seem to find a solid starting example point for building my own app in Electron… and I even had to dig to find the path.resolve(…) trick in the require(), so that’s not even documented.


Since I cannot seem to edit my original post(?), I thought I would point out that I have also tried using: