Documents for require('uxp').storage.FileSystemProvider

I’m just getting started with UXP, and I’m trying to understand the documents for the FileSystemProvider provided here:

https://developer.adobe.com/xd/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/

When I copy this example:

const folder = await fs.getFolder();
const myNovel = (await fs.getEntries()).filter(entry => entry.name.indexOf(‘novel’) > 0);
const text = await myNovel.read();

The console logs this error:
main.js:148 Local File system error: TypeError: Cannot destructure property ‘folder’ of ‘undefined’ as it is undefined.

Why does the example execute the getEntries method on fs, rather than on folder?

if you talking about an example getFolder(options) ,indeed it returns error.
firstly after FileSystemProvider got folder object, it’s not used in this code instead of FileSystemProvider assigned with getEntries method.
getEntries can work on folder object, as getFolder method picked folder object.
I tried and modified.

const fsProvider = require('uxp').storage.localFileSystem;
const getNovel = async () => {
  try {
    const folder = await fsProvider.getFolder();
    console.log(folder);
    if (folder === null) {
      console.log("canceled");
      return;
    }
    /*
    I replaced filter with find method. if you need to find a file, find is better.
    filter method returns an Array object. in case of filter method, you need to pick a File Object like this. myNovel[0]
     */
    // not fs.getEntries. folder Entry Object has getEntries method. and inspect files under the folder you picked.
    const myNovel = (await folder.getEntries()).find(entry => entry.name.indexOf('novel') > 0);
    // no any find "novel" file, it stops. make sure to prepare any text file "novel".
    if (myNovel === undefined) {
      console.log("no any file such a novel");
      return;
    }
    const text = await myNovel.read();
    console.log(text);
  } catch (e) {
    console.log(e);
  }
}

on addition that, read method can work on a File Entry object. not Array object. so that why I replaced filter with find. because filter method returns Array object even it gets only a value.

Thanks. The non-functional code provided in the tutorials and the documents cost me several days. Thanks again.