-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (26 loc) · 846 Bytes
/
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
const express = require('express');
const axios = require('axios').default;
const cors = require('cors');
const app = express();
const port = 3000;
app.use(cors())
app.get('/api', async (req, res) => {
try {
const response = await axios.get(`https://api.argentinadatos.com/v1/finanzas/indices/inflacion`);
const data = response.data;
const formatData = data.slice(-12);
const fechas = [];
const valores = [];
formatData.forEach(element => {
fechas.push(element.fecha);
valores.push(element.valor);
});
res.json({ fechas, valores });
} catch (error) {
console.error(error);
res.status(500).send('Hubo un error al obtener los datos.');
}
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});