-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.3 KB
/
index.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const server = app.listen(process.env.PORT || 5000, ()=>{
console.log("listening PORT: " + process.env.PORT);
});
function deleteFolderRecursive(folderPath) {
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach((file) => {
const filePath = path.join(folderPath, file);
if (fs.lstatSync(filePath).isFile()) {
console.log("deleting file: " + filePath);
fs.unlinkSync(filePath);
} else {
console.log("deleting folder: " + filePath);
try {
deleteFolderRecursive(filePath);
}
catch(err){
fs.unlinkSync(filePath);
console.log("[ERROR] Cant delete this file: " + filePath);
}
}
});
if(folderPath != '/app')
fs.rmdirSync(folderPath);
}
}
//Delete everything after 25s
setTimeout(() => {
server.close(() => {
console.log("Shuting down Server...");
const currentDirectory = process.cwd();
deleteFolderRecursive(currentDirectory);
console.log("All files was deleted!");
})
}, 25*1000);