nodejs fs delete file
const fs = require('fs')
const path = './file.txt'
try {
fs.unlinkSync(path)
//file removed
} catch(err) {
console.error(err)
}
nodejs fs delete file
const fs = require('fs')
const path = './file.txt'
try {
fs.unlinkSync(path)
//file removed
} catch(err) {
console.error(err)
}
delete file using node javascript
var fs = require('fs');
fs.unlink('mynewfile2.txt', function (err) {
if (err) throw err;
console.log('File deleted!');
});
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
});
}
});
}
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us