-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (25 loc) · 832 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
30
const PORT = 8000
const axios = require("axios").default;
const express = require("express")
const cors = require("cors")
require('dotenv').config()
const app = express()
app.use(cors())
app.get('/word', async (req, res) => {
const options = {
method: 'GET',
url: 'https://random-words5.p.rapidapi.com/getMultipleRandom',
params: {count: '2', wordLength: req.query.length},
headers: {
'X-RapidAPI-Key': process.env.RAPIT_API_KEY,
'X-RapidAPI-Host': 'random-words5.p.rapidapi.com'
}
};
axios.request(options).then((response) => {
console.log(response.data);
res.json(response.data[0])
}).catch((error) => {
console.error(error);
});
})
app.listen(PORT, () => console.log('server running on port ', PORT))