Update README.md

pull/2/head
Louis Chatriot 9 years ago
parent 90942cb662
commit 29a4b0151f
  1. 19
      README.md

@ -576,29 +576,26 @@ db.removeIndex('somefield', function (err) {
## Browser version ## Browser version
As of v0.8.0, you can use NeDB in the browser! You can find it and its minified version in the repository, in the `browser-version/out` directory. You only need to require `nedb.js` or `nedb.min.js` in your HTML file and the global object `Nedb` can be used right away, with the same API as the server version: The browser version and its minified counterpart are in the `browser-version/out` directory. You only need to require `nedb.js` or `nedb.min.js` in your HTML file and the global object `Nedb` can be used right away, with the same API as the server version:
``` ```
<script src="nedb.min.js"></script> <script src="nedb.min.js"></script>
<script> <script>
var db = new Nedb(); // Create an in-memory only datastore var db = new Nedb(); // Create an in-memory only datastore
db.insert({ planet: 'Earth' }); db.insert({ planet: 'Earth' }, function (err) {
db.insert({ planet: 'Mars' }); db.find({}, function (err, docs) {
// docs contains the two planets Earth and Mars
db.find({}, function (err, docs) { });
// docs contains the two planets Earth and Mars
}); });
</script> </script>
``` ```
It has been tested and is compatible with Chrome, Safari, Firefox, IE 10, IE 9. Please open an issue if you need compatibility with IE 8/IE 7, I think it will need some work and am not sure it is needed, since most complex webapplications - the ones that would need NeDB - only work on modern browsers anyway. To launch the tests, simply open the file `browser-version/test/index.html` in a browser and you'll see the results of the tests for this browser. If you specify a `filename`, the database will be persistent, and automatically select the best storage media available (IndexedDB, WebSQL or localStorage) depending on the browser.
If you fork and modify nedb, you can build the browser version from the sources, the build script is `browser-version/build.js`.
As of v0.11, NeDB is also persistent on the browser. To use this, simply create the collection with the `filename` option which will be the name of the `localStorage` variable storing data. Persistence should work on all browsers where NeDB works. Also, keep in mind that `localStorage` has size constraints, so it's probably a good idea to set recurring compaction every 2-5 minutes to save on space if your client app needs a lot of updates and deletes. See <a href="#compacting-the-database">database compaction</a> for more details on the append-only format used by NeDB. NeDB is compatible with all major browsers: Chrome, Safari, Firefox, IE9+. Tests are in the `browser-version/test` directory (files `index.html` and `testPersistence.html`).
**Browser persistence is still young! It has been tested on most major browsers but please report any bugs you find** If you fork and modify nedb, you can build the browser version from the sources, the build script is `browser-version/build.js`.
## Performance ## Performance

Loading…
Cancel
Save