How to access path module?

Here I made an example of how to get the directory, create a subfolder and save the active document with jpg extension.

  try {
      const path = app.activeDocument.path.replace(/\\[^\\]*$/, "")
      const Entrada = await fs.getEntryWithUrl(`file:${path}`); 

      const entries = await Entrada.getEntries();   
      let subfolder = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === "SubFolder");
      if (!subfolder) {subfolder = await Entrada.createFolder("SubFolder");}
      
      newFileName = app.activeDocument.name;
      var myFile = await subfolder.createFile(newFileName, { overwrite: true });
      let jpegOptions = {
          quality: 100,
          embedColorProfile: true
      }
      app.activeDocument.saveAs.jpg(myFile, jpegOptions, true);
  } catch (err) {alert(err)}

You can get more details in this dicursion Save Batch Images with Dynamic Name in Photoshop UXP