1

variable avatar is a file path, dont worry about it.

function rm (){
        fs.rm(avatar)
    }
writeStream.on("finish", rm())

but it is shows this error:

TypeError: callback is not a function
    at CB (internal/fs/rimraf.js:59:5)
    at internal/fs/rimraf.js:90:14
    at FSReqCallback.oncomplete (fs.js:171:23)
bahoz99
  • 121
  • 1
  • 6

2 Answers2

2

Change to writeStream.on("finish", rm). The presence of the () in rm() meant to call the function immediately and pass the return results (which is undefined) as the function argument which is certainly not what you want and thus why you got the error.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • @bahoz99 - Perhaps you have this same programming mistake in other parts of your code? If you want further help with this code, then show us more of the code and the exact error you're still getting. From the code you showed us, this is a required fix. It is also possible the `fs.rm()` requires a callback function (I don't know where that method comes from since it's not a standard part of the `fs` module). – jfriend00 Mar 31 '21 at 16:08
0

I was solved this problem.
I changed

function rm (){
        fs.rm(avatar)
    }

TO

function rm (){
        fs.unlinkSync(avatar)
        
    }
bahoz99
  • 121
  • 1
  • 6
  • 1
    This fix is NOT associated at all with the stack trace and error you showed in your question. Yes, this may be ANOTHER error you had in that code once you got the first one fixed via my answer. This is not actually an answer to the question you posed. – jfriend00 Mar 31 '21 at 16:25
  • it will be about syncs – bahoz99 Mar 31 '21 at 19:31