0

I'm working on a little side project and wanted to keep it as simple as possible. So app will have no back end, it will just be a single html page with some local javascript included that can be passed around and run locally.

Given those requirements, I'm looking for a some sort of solution that would let me store and load data like you would a database, in a way the data can be permanently stored in a file. So preferably, being able to use a json file like a NoSQL database.

I've looked at lowdb, alasql, and lokijs, but none of those seem to meet my requirements. They either need a node server to function, or only use local storage or memory to store data.

SpeedOfRound
  • 1,210
  • 11
  • 26
  • You could try [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API). Probably want to use a library that makes its use a bit easier. Would still have to load a file but could store it in local IDB while its in use. – pmkro Nov 28 '18 at 17:01

1 Answers1

1

You can't (except with an ugly workaround).

Such an application would require JavaScript to read/write from disk while running inside a webpage in a browser, and it's not technically possible. This has nothing to do with the file format.

However...

The workaround is to keep all the data in a JSON file, then load it dinamically via JavaScript (for example, with drag and drop). Then when you need to save it... you allow the modified JSON to be downloaded, and once downloaded you'd replace the old JSON with this new one, manually.

rodrigocfd
  • 6,450
  • 6
  • 34
  • 68
  • oof, guess I didn't realize how restricted js was when it comes to files – SpeedOfRound Nov 28 '18 at 17:16
  • @SpeedOfRound It's not really JavaScript as a language, it's the platform (the browser). You can use JavaScript and write a Node.js app which has normal read/write access to files, for example. – rodrigocfd Nov 28 '18 at 17:17