-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
59 lines (52 loc) · 1.49 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs");
let shell = require("shelljs");
const cron = require("node-cron");
const express = require("express");
let nodemailer = require("nodemailer");
app = express();
// deleting error.log files from server on the 21st of every month
cron.schedule("* * 21 * *", function() {
console.log("---------------------");
console.log("Running Cron Job");
fs.unlink("./error.log", err => {
if (err) throw err;
console.log("Error file succesfully deleted");
});
});
// sending emails at periodic intervals
// create mail transporter
let transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: "COMPANYPASS"
}
});
cron.schedule("* * * * Wednesday", function() {
console.log("---------------------");
console.log("Running Cron Job");
let mailOptions = {
from: "[email protected]",
to: "[email protected]",
subject: `Not a GDPR update ;)`,
text: `Hi there, this email was automatically sent by us`
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
throw error;
} else {
console.log("Email successfully sent!");
}
});
});
// To backup a database
cron.schedule("59 23 * * *", function() {
console.log("---------------------");
console.log("Running Cron Job");
if (shell.exec("sqlite3 database.sqlite .dump > data_dump.sql").code !== 0) {
shell.exit(1);
} else {
shell.echo("Database backup complete");
}
});
app.listen("3128");