Answers for "node delete files in directory"

2

node js delete folder with files

const fs = require('fs');

// directory path
const dir = 'temp';

// delete directory recursively
try {
    fs.rmdirSync(dir, { recursive: true });

    console.log(`${dir} is deleted!`);
} catch (err) {
    console.error(`Error while deleting ${dir}.`);
}
Posted by: Guest on July-23-2021
0

how to delete a folder using node js

fs.unlink('./node/myText.txt',function(){
    fs.rmdir('node');
});
Posted by: Guest on February-12-2021
0

delete file in Node.js

var fs = require('fs');
                    const url = '/media/uploads/' + uniqueFileName;
                    fs.access(url, fs.F_OK, async (err, ac) => {
                        if (err) {
                            return res.status(500).send({
                                message: "Error",
                                statusCode: 500
                            });
                        } else {
                            await fs.unlink(url, (ferr, fc) => {

                                if (ferr) {
                                    console.log('Error Occure On File Deletion!');
                                    return res.status(500).send({
                                        message: "Error",
                                        statusCode: 500
                                    });
                                } else {
//                                    saveDuplicatedUser();
                                    console.log('File deleted!');
                                    return res.status(200).send({
                                        message: "Error",
                                        statusCode: 200
                                    });
                                }
                            });
                        }
                    });
Posted by: Guest on July-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language