-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (63 loc) · 2.19 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
60
61
62
63
64
65
66
67
68
const express = require('express');
const app = express();
const fs = require(`fs`)
const bodyParser = require('body-parser');
const jsonParser = bodyParser.json()
const urlencodedParser = bodyParser.urlencoded({ extended: false })
const json = require("JSON")
const nodemailer = require('nodemailer');
const cryptojs = require('crypto-js');
const CryptoJS = cryptojs;
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'emidblol@gmail.com',
pass: process.env.password
}
});
const hash_token = process.env.hash_token
const token = process.env.token
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//read get all files from this folder
const files = fs.readdirSync(__dirname + "/pages/post")
//filter out this file
const filesfiltered = files.filter(file => file !== `index.js`)
//require all files
filesfiltered.forEach(file => require(`./pages/post/${file}`)(app,fs,json,nodemailer,cryptojs,CryptoJS,transporter,hash_token,token))
//require all files in pages/get
const filesget = fs.readdirSync(__dirname + "/pages/get")
filesget.forEach(file => require(`./pages/get/${file}`)(app,fs,json,nodemailer,cryptojs,CryptoJS,transporter))
//start server
app.listen(3000, () => {
console.log('server started');
});
//check if its someones birthday
function checkbirthday() {
var json_data = require('./database.json')
var date = new Date()
var day = date.getDate()
var month = date.getMonth() + 1
var year = date.getFullYear()
var today = `${day}.${month}.${year}`
for (var i in json_data.user) {
if (json_data.user[i].birthday === today) {
var mailOptions = {
from: 'emidblol@gmail.com',
to: i,
subject: 'Happy birthday!',
text: 'Happy birthday! I hope you have a great day!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
}
);
}
}
}