-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (60 loc) · 1.99 KB
/
index.js
File metadata and controls
77 lines (60 loc) · 1.99 KB
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
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const http = require('https');
const app=express();
app.set('view engine','ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
//connecting webpages
app.get("/",function(req,res){
res.render("home.ejs");
});
app.get("/home",function(req,res){
res.render("home.ejs");
});
app.get("/analyse",function(req,res){
res.render("analysis.ejs");
});
app.get("/pinescript.html",function(req,res){//not required
res.sendFile(__dirname + "/views/pinescript.html");
});
app.get("/guide",function(req,res){//not required
res.sendFile(__dirname + "/views/index.html");
});
app.get("/predict",function(req,res){//not required
res.sendFile(__dirname + "/views/index1.html");
});
app.get("/overview.html",function(req,res){//not required
res.sendFile(__dirname + "/views/overview.html");
});
app.get("/feedback",function(req,res){//not required
res.render("feedback.ejs");
});
//Analysis part
app.get('/daily-data', (req, res) => {
const apiKey = 'XWT4BU7NOC73D1HZ';
const symbol = req.query.symbol || 'APPL';
const apiUrl = `https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=${symbol}&apikey=${apiKey}`;
http.get(apiUrl, (apiRes) => {
let data = '';
apiRes.on('data', (chunk) => {
data += chunk;
});
apiRes.on('end', () => {
try {
const parsedData = JSON.parse(data);
res.json(parsedData);
} catch (error) {
console.error('Error parsing data:', error);
res.status(500).json({ error: 'Error parsing data' });
}
});
}).on('error', (error) => {
console.error('Error fetching data:', error);
res.status(500).json({ error: 'Error fetching data' });
});
});
app.listen(3000,function(){
console.log("Server started");
})