I'm working on the demo electron-quick-start project. I just added, in the main folder, a test.txt file and this in index.html :
<script>
const fs = require('fs');
alert(fs.readFileSync('test.txt')); // or ./test.txt or .\test.txt
</script>
It works. But now after having packaged the app with :
electron-packager . --platform=win32 --arch=ia32
when I run the packaged .exe app, it doesn't find the test.txt.
Probably because the test.txt is not in the same folder than the .exe but rather in resouces/app/test.txt.
What's the clean way to solve this electron-packager folder issue?
I solved it by using __dirname :
const path = require('path');
var datafile = path.join(__dirname, 'test.txt');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With