-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (71 loc) · 2.06 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
69
70
71
72
73
74
75
76
77
78
79
80
81
const express = require('express');
const bodyParser = require('body-parser');
const multer = require('multer');
const cloudinary = require('cloudinary').v2;
const path = require('path');
const mongoose = require('mongoose');
const dotenv = require("dotenv")
dotenv.config()
const app = express();
const port = 3000;
app.set("view engine","ejs");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.urlencoded({ extended: true }));
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
const upload = multer({ dest: 'uploads/' });
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET
});
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true });
const db = mongoose.connection;
const formSchema = new mongoose.Schema({
studentName: String,
email: String,
collegeName: String,
year: String,
department: String,
section: String,
rollNumber: String,
phoneNumber: String,
events: [String],
paymentScreenshot: String,
Transactionid:String
});
const Form = mongoose.model('Form', formSchema);
app.get("/",(req,res)=>{
res.render("index");
})
app.post('/submit', upload.single('paymentScreenshot'),async (req, res) => {
const { studentName, email, collegeName, year, department, section, rollNumber, phoneNumber,Transactionid } = req.body;
const events = req.body.events;
const result = await cloudinary.uploader.upload(req.file.path);
const paymentScreenshot = result.secure_url;
const formData = new Form({
studentName,
email,
collegeName,
year,
department,
section,
rollNumber,
phoneNumber,
events,
Transactionid,
paymentScreenshot
});
formData.save()
.then(() => {
res.status(200).send('Registered successfully');
})
.catch((err) => {
console.error(err);
res.status(500).send('Error submitting form data');
});
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});