Skip to content

Commit

Permalink
fix: create storage folder if not exists when trying to store setting…
Browse files Browse the repository at this point in the history
…s for the first time
  • Loading branch information
olzzon committed Dec 28, 2019
1 parent 3229936 commit 41dcb09
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/utils/SettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ export const loadSettings = (storeRedux: any) => {
return (JSON.parse(fs.readFileSync(path.resolve('storage', 'settings.json'))))
}
catch (error) {
console.log('Couldn´t read Settings.json file, creating af new')
saveSettings(settingsInterface);
return (settingsInterface);
}
};

export const saveSettings = (settings: any) => {
let json = JSON.stringify(settings);
if (!fs.existsSync('storage')){
fs.mkdirSync('storage');
}
fs.writeFile(path.resolve('storage', 'settings.json'), json, 'utf8', (error: any)=>{
console.log(error);
console.log('Error writing settings.json file: ', error);
});
};

Expand Down

0 comments on commit 41dcb09

Please sign in to comment.