-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 900 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
const express = require('express');
const axios = require('axios');
const cors = require('cors');
const app = express();
const port = 5000;
app.use(cors());
app.get('/api/pokemon', async (req, res) => {
try {
const response = await axios.get('https://pokeapi.co/api/v2/pokemon?limit=151');
res.json(response.data);
} catch (error) {
res.status(500).json({ error: 'Error fetching Pokemon data' });
}
});
app.get('/location/:idOrName', async (req, res) => {
try {
const { idOrName } = req.params;
const response = await axios.get(`https://pokeapi.co/api/v2/location/${idOrName}/`);
res.json(response.data);
} catch (error) {
console.error('Error fetching location data:', error);
res.status(500).json({error: 'Error getting location data'});
}
});
app.listen(3000, () => {
console.log(`Server running on port ${3000}`);
});