-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
101 lines (76 loc) · 2.03 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const express=require("express");
const bodyParser=require("body-parser");
const ejs=require("ejs");
const app=express();
const nodemailer=require('nodemailer');
//for checking the form is submitted
let result=false;
let checkError=false;
app.set("view engine",'ejs');
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("public"));
app.get("/",function(req,res){
res.render('home');
})
app.get("/about",function(req,res){
res.render('about');
})
app.get("/education",function(req,res){
res.render('education');
})
app.get("/skill",function(req,res){
res.render('skill');
})
app.get("/project",function(req,res){
res.render('project');
})
app.get("/achievement",function(req,res){
res.render('achievement');
})
app.get("/contact",function(req,res){
if (result===true)
{
result=false;
res.render('contact',{message:"Thanks for contacting me!"} );
}
else if(checkError===true)
{
checkError=false;
res.render('contact',{message:"Something went wrong! Please Try again."})
}
else
res.render('contact',{message:null});
})
app.post('/contact',function(req,res){
const {name,surname,email,subject,message}=req.body;
const transporter=nodemailer.createTransport({
service:'gmail',
auth:{
user:'919atul@gmail.com',
pass:'qfpqeqikkcsxzhpk'
}
});
const mailOptions={
from:email,
to:'919atul@gmail.com',
subject:subject,
text:'Name: '+name+' '+surname+'\nEmail: '+email+'\nMessage: '+message,
};
transporter.sendMail(mailOptions,function(error,info){
if(error){
console.log(error);
result=false;
checkError=true;
res.redirect("/contact");
}else{
console.log('Email sent: '+info.response);
result=true;
res.redirect('/contact');
// res.write('<script>alert("Thank You for Contacting me!");</script>');
// setTimeout(() => { res.redirect("/"); }, 5000);
}
});
});
app.listen(3000 || process.env.PORT,function(){
console.log("server is running on port 3000");
})