file_service

Pubbuild status

Angel service that persists data to a file on disk, stored as a JSON list. It uses a simplemutex to prevent race conditions, and caches contents in memory until changesare made.

The file will be created on read/write, if it does not already exist.

This package is useful in development, as it prevents you from having to installan external database to run your server.

When running a multi-threaded server, there is no guarantee that file operationswill be mutually excluded. Thus, try to only use this one a single-threaded serverif possible, or one with very low load.

While not necessarily slow, this package makes no promises about performance.

Usage

  1. configureServer(Angel app) async {
  2. // Just like a normal service
  3. app.use(
  4. '/api/todos',
  5. new JsonFileService(
  6. const LocalFileSystem().file('todos_db.json')
  7. ),
  8. );
  9. }