-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
72 lines (55 loc) · 1.77 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
const express = require("express");
const moment = require("moment");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const session = require("express-session");
const passport = require("passport");
const passportLocalMongoose = require("passport-local-mongoose")
const ejs = require("ejs");
const today = moment();
let currentDay = today.format('YYYY-MM-DD')
const app = express();
app.use(
session({
secret: "My name is Ayush",
resave: false,
saveUninitialized: false,
})
);
app.use(passport.initialize());
app.use(passport.session());
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static("public"));
const MONGODB_URI = "mongodb+srv://AyushKatoch:[email protected]/shop?retryWrites=true&w=majority";
mongoose.connect(MONGODB_URI , { useNewUrlParser: true });
const realDataSchema = new mongoose.Schema({
name: String,
historicalData : String,
historicalDataDate: Date,
popularTweet: String,
popularTweetNum: Number
});
const StatModel = new mongoose.model("StatModel", realDataSchema);
app.get("/", (req, res) => {
res.render("sentiment", {currentDay : currentDay })
})
app.post("/", (req, res, next) => {
const statModel = new StatModel({
name: req.body.realTimeData,
historicalData : req.body.historicalData,
historicalDataDate: req.body.historicalDataDate,
popularTweet: req.body.popularTweet,
popularTweetNum: req.body.popularTweetNum
})
statModel.save().then(result => {
console.log(result);
}).catch(err => {
console.log(err);
})
res.redirect("/");
})
app.listen(5000, () => {
console.log("Server Running on PORT 5000");
})