Storing Data in Electron JS Applications - 4 Methods

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024
  • 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.
    Code : github.com/cyr...
    Don't forget to Subscribe and hit the bell icon so that you'll get notified about my videos.
    #electronjs #programming #coding

Комментарии • 25

  • @talhazaryab
    @talhazaryab Год назад +2

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

  • @ramdomguyfiftychars
    @ramdomguyfiftychars Год назад +4

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

  • @Dungeon-Umami
    @Dungeon-Umami Год назад +3

    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 JSON.parse(fs.readFileSync(result.path));
    }
    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 globalThis.storage.w_storage({method: "write", path: "delete_me.json", data: Need_to_save});
    console.log("await_writing", await_writing);
    let Read_from_memory = await globalThis.storage.w_storage({method: "read", path: "delete_me.json", data: undefined});
    console.log("Read_from_memory", Read_from_memory);
    }
    herota123();

  • @arnabshanta
    @arnabshanta Год назад +1

    Just what I needed

  • @adamjones1951
    @adamjones1951 Год назад

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

  • @dipankarsahoo7119
    @dipankarsahoo7119 Год назад +1

    this really helped me a lot thanks sir

  • @senikouame4750
    @senikouame4750 Год назад

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

  • @andreicusnir8077
    @andreicusnir8077 Год назад +1

    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

  • @OmniaAb
    @OmniaAb 4 месяца назад

    very helpful, thank you

  • @jisonsoft4810
    @jisonsoft4810 5 месяцев назад

    Can you create a plugin architecture in electrons?

  • @vanbachucnguyen1831
    @vanbachucnguyen1831 3 месяца назад

    thanks for your instruction

  • @tripmad
    @tripmad Год назад

    Thank u for all your tutorials😊

  • @giriai
    @giriai Год назад

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

  • @arijitchakrabarty1552
    @arijitchakrabarty1552 Год назад

    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!

    • @coderjeet
      @coderjeet  Год назад +1

      I wouldn't use both. If you have data that needs to be saved, don't save it in browser sessions. Save it in a json file

    • @arijitchakrabarty1552
      @arijitchakrabarty1552 Год назад

      @@coderjeet understood. Thanks!

  • @allencorbalan5879
    @allencorbalan5879 Год назад

    super informative and helpful thanks!

  • @afnibi
    @afnibi 9 месяцев назад

    auto subs...thanks from indonesia

  • @ABentPaperclip
    @ABentPaperclip Год назад

    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...