Answers for "How to delete a file on Node.js"

7

nodejs fs delete file

const fs = require('fs')

const path = './file.txt'

try {
  fs.unlinkSync(path)
  //file removed
} catch(err) {
  console.error(err)
}
Posted by: Guest on February-10-2021
1

delete file using node javascript

var fs = require('fs');

fs.unlink('mynewfile2.txt', function (err) {
  
  if (err) throw err;
  console.log('File deleted!');
});
Posted by: Guest on July-18-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 "How to delete a file on Node.js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language