-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 741 Bytes
/
server.js
File metadata and controls
33 lines (28 loc) · 741 Bytes
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
const express = require('express');
const cors = require('cors')
const morgan = require('morgan')
const fetch = require('node-fetch')
const app = express()
app.use(cors())
app.use(morgan("coins"))
//routes
app.get("/coins", (req, res) => {
const url = "https://api.coinranking.com/v2/coins";
(async () => {
try {
await fetch(`${url}`, {
headers: { "x-access-token": `${process.env.COIN_RANKING_API_KEY}` }
}).then((response) => response.json())
.then((json) => {
console.log(json)
res.json(json)
})
} catch (error) {
console.log(error)
}
})()
})
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Listening on Port, ${port}`)
})