How to persist backup file




I am trying to backup app data in json file so that user can restore it later on. I can save and read file fine. However, when app is uninstalled, the backup file is also removed. Here is the code:

const file = fileSystemModule.knownFolders.documents().getFile('backup.json');

How can I make it so that backup file can always be restored later by user if he installs app again.

Thanks for the help

  1. You may use ExternalStorageDirectory to save your files which will not be removed upon uninstallation.
  2. You can back up your files regularly to your Cloud server (if any) or Google Drive (Android) / iCloud (iOS).


Thanks, can you please tell how to access this in nativescript or example usage of it within {N} app ? I see it is android core link instead of nativescript.



This documentation gives you an idea how you could use Java APIs in JS / TS (NativeScript).

You just have to pass the path to getFile method in file system module. Make sure you acquire the external storage permission with nativescript-permissions plugin.


sorry my bad, I had to give permission to app. Thanks for the pointers. :slight_smile:


In case anybody else has same problem, this worked for me:

const rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
const path = fileSystemModule.path.join(rootPath, fileName);
const file = fileSystemModule.File.fromPath(path);