1. const fs = require('fs');
  2. const path = require('path');
  3. const { promisify } = require('util');
  4. const readFile = promisify(fs.readFile);
  5. const writeFile = promisify(fs.writeFile);
  6. /**
  7. * Mirrors data from a source file to a destination file.
  8. *
  9. * @param {object} config - Configuration object containing source and destination file paths.
  10. * @param {string} config.source - Path to the source file.
  11. * @param {string} config.destination - Path to the destination file.
  12. */
  13. async function mirrorFile(config) {
  14. try {
  15. const sourceFilePath = path.resolve(config.source);
  16. const destinationFilePath = path.resolve(config.destination);
  17. // Read the source file
  18. const sourceData = await readFile(sourceFilePath, 'utf8');
  19. // Write the data to the destination file
  20. await writeFile(destinationFilePath, sourceData, 'utf8');
  21. console.log(`Successfully mirrored ${sourceFilePath} to ${destinationFilePath}`);
  22. } catch (error) {
  23. console.error(`Error mirroring file: ${error.message}`);
  24. }
  25. }
  26. module.exports = mirrorFile;

Add your comment