pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Profile.json gets baked into .exe

Open jpall12 opened this issue 5 years ago • 1 comments

Hi, I want to be able to edit my Profile.json and have my code be able to read any new changes, but when packaging it bakes in the profile.json there for I'm not able to edit it. How should I go about importing this json file.

jpall12 avatar Mar 19 '21 20:03 jpall12

Use fs to read a file on runtime and leave Profile.json out while packaging.

Example:

const fs = require('fs')

fs.readFile("Profile.json", "utf8", function (err, json) {
    if (err) console.error(err)
    else {
        const profile = JSON.parse(json);
        // your code
    }
}

Note that Profile.json has to be in the same directory as the .exe in this example. You also can define a path to a subfolder on fs.readFile().

tancred423 avatar Mar 31 '21 14:03 tancred423