-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (33 loc) · 855 Bytes
/
index.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
const express = require('express')
const CoinGecko = require('coingecko-api')
const app = express()
app.use(express.json())
app.use((err, req, res, next) => {
if (err) {
console.log('Invalid Request data')
res.send('Invalid Request data')
} else {
next()
}
})
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
})
let prices = {}
async function updatePrice() {
const CoinGeckoClient = new CoinGecko()
const { data } = await CoinGeckoClient.simple.price({
ids: ['ethereum'],
vs_currencies: ['usd']
})
console.log(data)
prices = data
setTimeout(updatePrice, 10000)
}
app.get('/', function (req, res) {
res.json(prices)
})
app.listen(8000)
updatePrice()