Save a picture without batchPlay

I am trying convert my old plugin to UXP.

I stuck at saving layers as png ro jpeg files. My old code is

    var doc = app.activeDocument;
    var file = new File(filePath);
    var opts = new PNGSaveOptions();
    doc.saveAs(file, opts, true);

After UXP I changed my code like this.

  const userFolder = require('uxp').storage.localFileSystem;
  const file = await userFolder.createFile(`${filePath}/${fileName}.png`);
  const activeDocument =  app.activeDocument;
  return activeDocument.save(file);

I had look for some examples from starter project here . But can’t find something I need.

When I search in forum topics, saw batchPlay. I really don’t understand what it is and looks weird after my code.

How can I save png or jpeg in right way?

Thanks.