-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (26 loc) · 743 Bytes
/
script.js
File metadata and controls
29 lines (26 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const File = require('./models/file')
const fs =require('fs')
const connectdb =require('./config/db')
connectdb()
async function fetchd(){
const dlimit = 24*60*60*1000
const pastdate = new Date(Date.now() - dlimit)
const files=await File.find({createdAt:{$lt:pastdate}})
if(files.length){
for(const file of files)
{
try
{
fs.unlinkSync(file.path)
await file.remove()
console.log(`Succesfully file ${file.filename} deleted after 24hrs `)
} catch(err){
console.log(`Error while deleting file ${err}`)
}
}
console.log('Job of deletion done!')
}
}
fetchd().then(()=>{
process.exit()
})