Storing Data in Electron JS Applications - 4 Methods

preview_player
Показать описание
Every app requires storing some sort of data. Earlier I made a video about using Sqlite with Electron, in this video I am going to show you 4 other ways of storing data in Electron.

These methods are suitable for smaller pieces of data that can be stored in key value pairs.

The methods are
- Flat JSON file,
- sessionStorage
- localStorage
- IndexedDb

You can store data in IndexedDb on both the renderer and the main process.

Watch this video to see these storage methods in detail.

Don't forget to Subscribe and hit the bell icon so that you'll get notified about my videos.

#electronjs #programming #coding
Рекомендации по теме
Комментарии
Автор

I wish your channel grow fast. Your content is rare.

talhazaryab
Автор

Thank you very much! This helps a ton! Working on a hobby project to play around with Electron+Vite+Vue here :D

ramdomguyfiftychars
Автор

I did it like this:
preload.js:
const {contextBridge, ipcRenderer} = require('electron');
contextBridge.exposeInMainWorld('storage', {
w_storage: (data)=>ipcRenderer.invoke('storage', data)
});

main_node.js:
const fs = require("fs");
ipcMain.handle('storage', (e, result)=>{
if(result.method === 'read'){
if (fs.existsSync(result.path)) return
}
if(result.method === 'write'){
fs.writeFileSync(result.path, JSON.stringify(result.data, null, 2));
return "data saved";
}
});

window.js:
async function herota123(){
let Need_to_save = {lol: "kek", che: ["bu", "rek"]};
let await_writing = await "write", path: "delete_me.json", data: Need_to_save});
console.log("await_writing", await_writing);
let Read_from_memory = await "read", path: "delete_me.json", data: undefined});
console.log("Read_from_memory", Read_from_memory);
}
herota123();

Dungeon-Umami
Автор

this really helped me a lot thanks sir

dipankarsahoo
Автор

Can you create a plugin architecture in electrons?

jisonsoft
Автор

Hey I have a question. Would it work with Electron version 23.1.3 and Angular 15? I have tried to save the data with Electron-store from ngx-electron but it failed. I also used IPC to store the data and again, fail. Are there other alternatives? Would be very happy to get an answer. Thanks

andreicusnir
Автор

How do we write multiple data points to the file instead of overwriting the pre-existing data?

adamjones
Автор

if I use js Fill how can I, make CRUD system with it ??

senikouame
Автор

Quite insightful! Thanks! Quick question: I have a routine manager application. In it, I want to give the user the ability to store routines. Should I use IndexedDB for that or would storing it in a local json file be better? Thanks!

arijitchakrabarty
Автор

But how did you write file on MAS? MAS doesn't allow you to write data to disk...

giriai
Автор

you never actually showed how the json data gets out of an object in main.js back to render- you're just logging it to the console, which isn't enough to re-populate your form...

ABentPaperclip