File path confusion


I hope someone can help me with the semantics of filepaths in my electron app.

I am porting from a webapp; my public assets are in a subdirectory (I’m on Linux) named public, but I find that this doesn’t work:

mainWindow.loadURL('file://' + __dirname + 'public/index.html');

In order to get electron to run, I had to move index.html (and other contents of the public directory) into the same directory where I start Electron, and leave the path like this:

mainWindow.loadURL('file://' + __dirname + '/index.html');

Also for other assets in my tree I find I have to specify a full Linux filepath to get at them, and that using ~ in the pathname doesn’t work.

Could someone point me to where I could read up on the rules for specifying paths?


__dirname points at the folder that the main.js is being run from in.

So in the first instance, it’s looking for a public folder within the directory where main.js lives, and then an index.html inside that.

If you’re not happy doing it using an absolute path, you could wrangle with Node’s path module: