-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (41 loc) · 1.14 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
49
50
51
52
53
var express = require("express");
var request = require("request");
var bodyParser= require("body-parser");
var app = express();
var path = process.cwd();
require("dotenv").load();
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use("/public", express.static(path+"/public"));
app.get("/",function(req,res){
res.sendFile(path+"/public/home.html");
})
app.get("/initial",function(req,res){
var symbol = "AAPL";
url = "https://www.quandl.com/api/v3/datasets/WIKI/"+
symbol+".json?limit=30&collapse=weekly&api_key="+process.env.API_KEY;
request(url,function(err,response,body){
if(JSON.parse(body)["quandl_error"]){
res.send("error");
}
else{
res.send(body);
}
});
})
app.post("/add/symbols",function(req,res){
var symbol = req.body.symbol;
url = "https://www.quandl.com/api/v3/datasets/WIKI/"+
symbol+".json?limit=30&collapse=weekly&api_key="+process.env.API_KEY;
request(url,function(err,response,body){
if(JSON.parse(body)["quandl_error"]){
res.send("error");
}
else{
res.send(body);
}
});
});
app.listen(8080,function(){
console.log("App is listening on port %s.",8080);
})