Is there any localStorage for electron?


While running my electron desktop App, I want to store images to some localStorage of electron. Can someone plz help me?? Is there any NPM localStorage for electron?


Not sure if you can directly access localStorage, but you can easily persist data without it – just store any data locally using regular node.js file methods. This would more suited for files than localStorage anyway. For JSON data can also use something like electron-json-storage.


I have tried using electron-json-storage but could not find the location of the saving data… @lauris


From the README file:

[…] write and read JSON objects to/from operating system application data directory, as defined by app.getPath(‘userData’)

If you are not sure where your operating system application data directory is located, you can just check the value of app.getPath(‘userData’), for example like this console.log(app.getPath(‘userData’))


Thank you so muc it worked and i found the JSON file. :slight_smile:


You can use the normal browser localStorage system. It is only accessible to the renderer process.


EDIT : As pointed out by @idleberg. I’m wrong with ‘You can’t …’. I was confused by another similar issue.

You can’t. I’m sure you must also be getting an error in console. localStorage, IndexedDB and such do not work over file:// protocol.

Very glad that I made decision to serve my app inside webview. I get all the goodness of browser, plus I can inject any node API’s as needed.

And on top of that I can port minimal version of my app to web browsers any day with little modifications.

And the best of all, I don’t have to worry about delivering app updates. Any updates are applied using ServiceWorkers inside webview. Good for a rolling release model.


I don’t think that’s correct. Atom stores data in both, localStorage and IndexedDB

I also checked other Electron apps (Visual Studio Code and Kap), and they all let you save data persistently in localStorage and IndexedDB.


HTML5 localStorage works in Electron, I’m using a js library called “stash.js” to simplify the operation. Other libraries that utilize HTML5 localStorage should work too in most cases.

Nothing special in main.js required

The example on the Github page worked fine