Reading and writing data
As soon as your RemoteStorage instance is ready
for action (signaled by the
ready event), we can start reading and writing
One of the unique features of rs.js is that users are not required to have their storage connected in order to use the app; you can require connecting storage if it fits your use case. Any data written locally is automatically synced to the remote storage server when connecting an account.
BaseClient instance is the main endpoint for interacting with storage:
listing, reading, creating, updating and deleting documents, as well as
handling change events.
Check out the BaseClient API docs in order to learn about all functions available for reading and writing data and how to use them.
There are two options for acquiring a BaseClient instance:
Quick and dirty: creating a client via
This should mainly be used for manually exploring client functions and in
scope(), you can create a new BaseClient scoped to a
const client = remoteStorage.scope('/foo/'); // List all items in the "foo/" category/folder client.getListing('') .then(listing => console.log(listing)); // Write some text to "foo/bar.txt" const content = 'The most simple things can bring the most happiness.' client.storeFile('text/plain', 'bar.txt', content) .then(() => console.log("data has been saved"));
The recommended way: using clients in data modules
The recommended way is to use the private and public
which are available in so-called data modules. Continue
to the next section in order to learn about them.