Hello can someone help me pls I want to retrieve data from a server database to an application via json, I don’t have any problems with the server, and have token the data into the app, but I want to save this data into the local database (another json file which is database)by using javascript. Thanks
-
Is this a browser -> server type request? Try LocalStorage (https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API) – lxe May 14 '15 at 18:34
-
possible duplicate of [Storing Objects in HTML5 localStorage](http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage) – Alejandro Teixeira Muñoz May 14 '15 at 18:34
-
LocalStorage will allow you to save as a key/val pair. You will have to stringify your json when setting and re-parse when you want to use it. – Rob May 14 '15 at 18:36
2 Answers
Well considering it's just json and you want to save that locally, you could just save it as a .json
file somewhere on the disk, perhaps using something like fs

- 3,576
- 2
- 13
- 24
You can use LocalStorage or SessionStorage to store your data in key value pairs.
If you want something more advanced I can recommend using localStorageDb wich is a database layer for those two.
An example:
var db = new localStorageDB("myDb", localStorage);
db.createTable("Persons", ["name", "surName", "birthDate"]);
db.insert("Persons", {name: "John", surName: "Doe", birthDate: new Date()});
db.commit()
Amplify.js will serve too with the advantage of being persistence agnostic, that is if LocalStorage is not supported it will fallback to another mechanism to store your data but lacks the database functionality.
If your database is large enough you should use IndexedDb or Web SQL. the main problem here beign compatibility. Check http://caniuse.com/indexeddb and http://caniuse.com/sql-storage
You can use this library https://github.com/yathit/ydn-db, it has support for schema generation, transactions, query support and client-server syncronization.

- 3,665
- 1
- 26
- 40