-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (59 loc) · 1.66 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
require("dotenv").config();
var cors = require('cors')
var express = require("express"),
request = require("request"),
bodyParser = require("body-parser"),
app = express();
app.use(cors())
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
app.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
var seeds = require("./seeds.js");
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.get("/", (req, res) => {
res.render("home");
});
app.get("/twitteranalysis", (req, res) => {
res.render("twitter");
});
// var interval = setInterval(function () {
// request(
// "https://twittersentimentanalyticsback.herokuapp.com/notif",
// function (err, response, body) {
// if (!err && response.statusCode === 200) {
// var notif = JSON.parse(body);
// console.log(notif);
// }
// }
// );
// }, 3000);
app.get("/analyze", (req, res) => {
var query = req.query;
var count = req.query.ntwts;
console.log(query['searchtrend'])
request(
"https://twittersentimentanalyticsback.herokuapp.com/analyze?query=" + query['searchtrend'],
function(err, response, body) {
if (!err && response.statusCode === 200) {
var tweetsAnalysis = JSON.parse(body);
console.log(tweetsAnalysis);
res.json(tweetsAnalysis);
}
}
);
// to get data from the seeds file for testing purposes
// var tweetAnalysis = seeds;
// res.json(tweetAnalysis);
});
app.listen(process.env.PORT, process.env.IP, () => {
console.log("Server started!!");
});