0

I am a beginner to nodejs please help me find this solution?

I need code that looks at a file and makes a backup of the file whenever it is changed and saved to the disk.

  1. have to create backup in separate folder.
  2. filenofoundexception if no particular file is not exists
  3. changes are watched and saved immediately and console it
    const fs = require('fs');
    
    fs.watchFile("sample.txt", {
        persistent: true,
        interval: 2000,
    }, (curr, prev)=>{
        fs.writeFile('backupFile.text', prev)
    })

I tried got this error

node:internal/validators:223
    throw new ERR_INVALID_CALLBACK(callback);
    ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
JJ Asghar
  • 614
  • 5
  • 15
storm
  • 43
  • 8
  • Check the full stack trace; are you sure it's coming from here? (Also noting the docs indicate `fs.watch` is preferred.) – Dave Newton Apr 26 '22 at 17:11
  • ya it worked, from where can i get previous file content, to store to another file – storm Apr 27 '22 at 14:09

0 Answers0