javascriptnode.jssqliteelectroncreate-react-app

How can I access the sqlite3 database file in production with electron?


I have a electron app, and I use it together with the create-electron-app.

My electron main process file resides in the public folder, and so does my sqlite3 database.

When I reference the database in development it works as expected because I can access the path: F:\www\project-name\public\api\db\demodb01

But in production the path does not exist (hidden behind app.asar I'd say): C:\Users\userName\AppData\Local\Programs\project-name\resources\app.asar\build\api\db\demodb01

How can I target the database file in production?


Solution

  • When storing files in your application you should use app.getPath('userData') to store them outside of your applications scope, which keeps them persisted.

    nedb is a common choice for Electron applications since it's a lightweight database written in JavaScript. If you haven't checked it out, I recommend you to do.