How to persist data in an Electron app?

前端 未结 9 1131
刺人心
刺人心 2021-01-30 07:00

I\'ve been scouring the Electron documentation to try and figure out how to persist data in an Electron app. For example, in iOS or OS X, you could use NSUserDefaults to store u

9条回答
  •  被撕碎了的回忆
    2021-01-30 07:29

    Electron views are built with Webkit which gives you access to the web based localstorage api. Good for simple and easy settings storage.

    If you need something more powerful or need storage access from the main script, you can use one of the numerous node based storage modules. Personally I like lowdb.

    With most node storage modules, you will need to provide a file location. Try:

    var app = require('app');
    app.getPath('userData');
    

提交回复
热议问题