node check if file exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}
node check if file exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}
delete with unlinksync node
const fs = require('fs')
const path = './file.txt'
try {
fs.unlinkSync(path)
//file removed
} catch(err) {
console.error(err)
}
python create file if not exists
import os
if not os.path.exists(path):
with open(path, 'w'):
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