Skip to content
Advertisement

Tag: fs

How to delete all pictures of an directory

I am trying to delete all pictures of an directory. But getting error on directory path. And also dont know how to get all pictures path & delete all of them. My directory structure : I have tried this : But getting error : Cannot find module ‘../tmp/upload’ Need help to get the path & all pictures on upload folder

Copy folder recursively in Node.js

Is there an easier way to copy a folder and all its content without manually doing a sequence of fs.readir, fs.readfile, fs.writefile recursively? I am just wondering if I’m missing a function which would ideally work like this: Regarding this historic question. Note that fs.cp and fs.cpSync can copy folders recursively and are available in Node v16+ Answer Since Node

How to append to a file in Node?

I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string. Any idea how to do this the easy way? Answer For occasional appends, you can use appendFile, which creates a new file handle each time it’s called: Asynchronously: Synchronously: But if you append repeatedly to the same

Advertisement