forked from Trac-Systems/intercom
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (27 loc) · 697 Bytes
/
server.js
File metadata and controls
34 lines (27 loc) · 697 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
34
const express = require("express");
const axios = require("axios");
const app = express();
const PORT = 3000;
app.use(express.static("public"));
app.get("/api/price/:coin", async (req, res) => {
try {
const coin = req.params.coin;
const response = await axios.get(
`https://api.coingecko.com/api/v3/coins/${coin}/market_chart`,
{
params: {
vs_currency: "usd",
days: 7
}
}
);
res.json({
prices: response.data.prices
});
} catch (err) {
res.status(500).json({ error: "Coin not found" });
}
});
app.listen(PORT, () => {
console.log(`Severy Crypto Live Price running at http://localhost:${PORT}`);
});