-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (51 loc) · 1.27 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
// jshint esversion: 6
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const api = require("./controller/api");
const ejs = require("ejs");
const data = require("./data.js");
const fs = require("fs");
const app = express();
const port = process.env.PORT || 3000;
// Global variables
app.set("view engine", "ejs");
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.use(express.static("public"));
// Mongodb database
// mongoose.connect(process.env.DB_URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// });
// connecting mongoDB locally.
mongoose.connect("mongodb://localhost:3000:27017/teachersBayDB", {
useNewUrlParser: true,
useUnifiedTopology: true
});
// GET for /
app.get("/", (req, res)=>{
res.render("index");
});
app.get("/api/v1", (req, res)=>{
let data = api.sendData();
res.send(data);
// fs.appendFileSync('data.json', data);
});
app.get("/submit", (req, res)=>{
res.render("submit");
});
app.post("/submit", (req, res)=>{
console.log(req.body);
});
app.get("/*", (req, res)=>{
res.send("LOL Not found");
});
app.listen(port, ()=>{
console.log("Server running at 3000");
});
for(let i=0; i<data.length; i++){
console.log(`${data[i]} ${i}`);
}