2024-10-12 10:35:14 +00:00
# File Service for Protevus
2021-06-26 12:06:30 +00:00
2022-01-04 12:03:52 +00:00

2021-06-10 08:47:05 +00:00
[](https://dart.dev/null-safety)
2024-07-07 15:02:49 +00:00
[](https://discord.gg/3X6bxTUdCM)
2024-10-12 10:35:14 +00:00
[](https://github.com/dart-backend/protevus/tree/master/packages/file_service/LICENSE)
2021-06-10 08:47:05 +00:00
2024-10-12 10:39:20 +00:00
Protevus service that persists data to a file on disk, stored as a JSON list. It uses a simple mutex to prevent race conditions, and caches contents in memory until changes are made.
2017-06-13 16:55:07 +00:00
The file will be created on read/write, if it does not already exist.
2022-01-04 12:03:52 +00:00
This package is useful in development, as it prevents you from having to install an external database to run your server.
2017-06-13 16:55:07 +00:00
2022-01-04 12:03:52 +00:00
When running a multi-threaded server, there is no guarantee that file operations will be mutually excluded. Thus, try to only use this one a single-threaded server if possible, or one with very low load.
2017-06-13 16:55:07 +00:00
While not necessarily *slow* , this package makes no promises about performance.
2021-06-26 12:06:30 +00:00
## Usage
2017-06-13 16:55:07 +00:00
```dart
2024-10-12 10:39:20 +00:00
configureServer(Protevus app) async {
2017-06-13 16:55:07 +00:00
// Just like a normal service
2017-12-21 06:37:03 +00:00
app.use(
'/api/todos',
2022-01-04 12:03:52 +00:00
JsonFileService(
2017-12-21 06:37:03 +00:00
const LocalFileSystem().file('todos_db.json')
),
);
2017-06-13 16:55:07 +00:00
}
2021-06-26 12:06:30 +00:00
```