-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (48 loc) · 1.47 KB
/
app.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
// Dependencies
// ================================================
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
const hostname = '127.0.0.1';
const port = 3000;
// Configuring body parser
// ================================================
app.use(bodyParser.urlencoded({ extended: false}));
app.use(bodyParser.json());
// Connecting static directory
// ================================================
app.use('/static', express.static(__dirname + '/static'));
// Configuring templates
// ================================================
app.set('views', './views');
app.set('view engine', 'pug');
// Routes
// ================================================
app.get('/', function(req, res){
res.render('home', {message: 'Welcome to StraightFacts!'})
});
app.post('/', function(req, res){
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: "[email protected]",
pass: ""
}
});
const mailFields = {
to: req.body.Email,
subject: "StraightFact of the Day",
text: req.body.Fact
};
transporter.sendMail(mailFields, function(error, data){
if (error){
console.log(error);
} else {
console.log('Email sent: ' + data.response);
}
});
});
// Start the server
// ================================================
app.listen(port, hostname, () => console.log(`App listening on port ${port}`));