I want to copy the particular text in a file to another file including all content in Node js

Solution for I want to copy the particular text in a file to another file including all content in Node js
is Given Below:

.bs-section--sample-page {
  padding: 25px 0;
  background-image: linear-gradient(102deg, var(--violet-blue) 0%, #002362);
  .media-elements {
    position: relative;
    figure {
      position: absolute;
      top: 4px;
      left: 10px;
      width: 19px;
      height: 15px;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
  }
    }
  }
}

@include media-breakpoint-down(md){
  .bs-section--domain-enter {
   &.bs-section--platform-domain{
     display: none;
   }
  }
}

I want to copy the above text above into another file(including the between text also and only the text that contains @include media-breakpoint-down(md){——-} ) in Node js.

this is my code

function searchFilesInDirectory(dir, filter, ext) { if
(!fs.existsSync(dir)) {
console.log(Specified directory: ${dir} does not exist);
return; }

const files = getFilesInDirectory(dir, ext);

files.forEach((file) => {
const fileContent = fs.readFileSync(file);

// We want full words, so we use full word boundary in regex.
const regex = new RegExp("\b" + filter + "\b");
if (regex.test(fileContent)) {
  console.log(`Your word was found in file: ${file}`);

  fs.readFile(`${file}`, { encoding: "utf-8" }, (err, data) => {
    if (err) {
      console.error(err);
      return;
    }
    // let str = data;
    let dataArray = data.split("n"); // convert file data in an array

    function extractString(template, initChar, finalChar) {
      let i = 0;
      let str = [dataArray];
      do {
        if (template[i] == initChar) {
          for (let j = i + 1; j < template.length; j++) {
            if (template[j] == finalChar) {
              dataArray[str.length] = template.slice(i + 1, j);
              i = j + 1;
              break;
            }
          }
        }
      } while (++i < template.length);
      console.log(dataArray);
      return dataArray;
    }

    // extractString(dataArray);

    // const word = "media-breakpoint-down{";
    // const matches = dataArray.matchAll(/media-breakpoint-down (.*?) dad/g);

    // const start = `media-breakpoint-down{`;
    // const end = `}`;
    // const searchKeyword = dataArray.split(start)[1].split(end)[0];
    // console.log(middleText)

    const searchKeyword = `@include media-breakpoint-up(lg) { \ }`; // we are looking for a line, contains, key word 'user1' in the

file
let lastIndex = -1; // let say, we have not found the keyword

    for (let index = 0; index < dataArray.length; index++) {
      if (dataArray[index].includes(searchKeyword)) {
        // check if a line contains the 'media-breakpoint-down' keyword
        lastIndex = index; // found a line includes a 'media-breakpoint-down' keyword
        break;
      }
    }

    dataArray.splice(lastIndex, 1); // remove the keyword 'media break point word' from the data Array

    // UPDATE FILE WITH NEW DATA
    // IN CASE YOU WANT TO UPDATE THE CONTENT IN YOUR FILE
    // THIS WILL REMOVE THE LINE CONTAINS 'user1' IN YOUR shuffle.txt FILE
    const updatedData = dataArray.join("n");
    fs.writeFile(
      "C:/xampp/htdocs/berg-dev-env/wp-content/themes/berg-theme/assets/scss/block/bs-section/bs-section--test-mobile.scss",
      updatedData,
      (err) => {
        if (err) throw err;
        console.log("Successfully updated the file data");
      }
    );

    //for every files in the directory
    // files.forEach(function(filename) {
    //   // fs.writeFile(filename, CONTENTS, function(err) {
    //   //   console.log('File written:', filename);
    //   // });
    //   fs.writeFile(
    //     filename+"-mobile",
    //     updatedData,
    //     (err) => {
    //       if (err) throw err;
    //       console.log("Successfully updated the"+`${filename}`+"data");
    //     }
    //   );
    // });

    console.log(dataArray);
    // console.log(dataArray.search("media-breakpoint-down"));
    // console.log(dataArray.indexOf("media-breakpoint-down"));
  });
}   }); }