Search code examples
javascriptnode.jsthrow

Javascipt copyFile throw error and continue


I am looking for a way to continue program execution for fs.copyFile is error is thrown.

 fs.copyFile(file_from, file_to, (err) => {
    if (err) throw err;
    continue;
 });

As of now, if there is an error the app stops running. I would like to avoid that.


Solution

  • Ideally I would like to get an error message in a console but continue with execution after that.

    I think you could just do that:

    fs.copyFile(file_from, file_to, (err) => {
      if (err) console.log(err);
    });