Hello,
I am having some issues keeping a config file that is written the first time the snap runs. I am using NodeJS to handle this and I am thinking there must be another was (as it’s not working)…
Here is what the NodeJS code does:
-
It Checks
fs.existsSync(process.env.SNAP_COMMON + '/config.json')
to see if my config file is there. -
If it does not find it, the file is then created with
fs.writeFile(process.env.SNAP_COMMON + '/config.json', {some json}, 'utf8', callback(err) )
. The config file holds an ID from a web service that can only be requested once. If the request is made again it will return a new ID. -
Then the rest of my app runs as normal.
NOTE: All of this is working - if the file does not exist it will create it, and write to it. My issue is when the device is restarted or unplugged then powered back on it goes to create a new config file thus grabbing a new ID.
So my question: How should I be storing and persisting configuration data that should only be generated once in the lifetime of the device (the configuration file should not be overwritten on refresh or even a new version of the snap it should persist after the first creation)?
Should I be creating the config files with a hook? Any help would be wonderful!
Thanks for the help in advance!!