-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
62 lines (46 loc) · 1.87 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
// import environmental variables from our .env file
require('dotenv').config({ silent: true });
const express = require('express');
const app = express();
const routes = require('./routes');
const cron = require("node-cron");
const mailer = require('./services/mailer').transporter;
const tasks = require('./tasks');
// Make sure we are running node 7.6+
const [major, minor] = process.versions.node.split('.').map(parseFloat);
if (major < 7 || (major === 7 && minor <= 5)) {
console.log('🛑 🌮 🐶 💪 💩\nHey You! \n\t ya you! \n\t\tBuster! \n\tYou\'re on an older version of node that doesn\'t support the latest and greatest things we are learning (Async + Await)! Please go to nodejs.org and download version 7.6 or greater. 👌\n ');
process.exit();
}
app.set('port', (process.env.PORT || 3000));
// 0 0 0 * * *
//send user news update from ycombinator everyday
cron.schedule('0 0 0 * * *', async function () {
try {
await tasks.getNews();
const attachments = [{ filename: 'news.pdf', path: __dirname + '/assets/news.pdf', contentType: 'application/png' }];
const mailOptions = {
from: process.env.email, // sender address
to: 'Abimbola130@gmail.com', // list of receivers
subject: 'Y-Combinator news daily updates', // Subject line
attachments,
// html: '<p>Your html here</p>'// plain text body
};
mailer.sendMail(mailOptions, function (err, info) {
if (err) {
console.log(err.message)
}
else {
console.log('sent');
}
});
console.log('send news to user email');
}
catch (err) {
console.log(err.message);
}
});
app.use('/', routes);
const server = app.listen(app.get('port'), () => {
console.log('server up and running', server.address().port);
});