-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (39 loc) · 1.2 KB
/
server.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
//Include the necessary extensions
const express = require("express");
const mongoose = require("mongoose");
const bodyparser = require("body-parser");
const app = express();
//encode url
app.use(bodyparser.urlencoded({extended: true}));
//connecting to mongoDB
mongoose.connect("mongodb+srv://username:[email protected]", { useNewUrlParser: true }, { useUnifiedTopology: true });
// Create data Schema
const regSchema = {
Towed: String,
licencePlete: String,
reason: String,
note: String,
attachtment: String
}
const Reg = mongoose.model("Details", regSchema);
//To present the html page
app.get("/", function(req, res) {
res.sendFile(__dirname + "/main.html");
})
//Send data to mongoDB
app.post("/", function(req, res) {
let newReg = new Reg({
Towed: req.body.towed,
licencePlete: req.body.licencePlete,
reason: req.body.reason,
note: req.body.note,
attachtment: req.body.attachtment
});
newReg.save();
//Remain on thesame page after submition
res.redirect("/");
})
// To listen on PORT 3000
app.listen(3000, function() {
console.log("Listening on 3000");
})