-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (34 loc) · 1.16 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
const express = require("express");
const app = express();
// The form data is sent in the POST request body. To extract it,
// use the express.urlencoded() middleware, provided by Express
app.use(express.urlencoded({ extended: true }));
const path = require("path");
const router = express.Router();
router.post("/addContact", function(req, res) {
const name = req.body.name;
const email = req.body.email;
const message = req.body.message;
res.sendFile(path.join(__dirname + "/public/alertMessageContactMe.html"));
// send email with nodemailer:
var sendEmail = require("./sendEmail");
var mailOptions = {
from: "", // email address
to: "", // email address
subject: "mindaugas.pro website message",
text: "new entry to mongodb: " + name + " " + email + " " + message
};
sendEmail.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
});
// Set static folder
app.use(express.static(path.join(__dirname, "public")));
//add the router
app.use("/", router);
app.listen(process.env.port || 3000);
console.log("Running at Port 3000");