-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (30 loc) · 955 Bytes
/
Copy pathserver.js
File metadata and controls
35 lines (30 loc) · 955 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
35
const PORT = 8000
const express = require('express')
const cors = require('cors')
const axios = require('axios')
const app = express()
require('dotenv').config()
app.use(cors())
app.get('/', (req,res) => {
res.send('helo')
})
app.get('/translete', (req,res) =>{
const fromLanguage = req.query.from
const toLanguage = req.query.to
const text = req.query.text
const options = {
method: 'GET',
url: 'https://nlp-translation.p.rapidapi.com/v1/translate',
params: {text: text, to: toLanguage, from: fromLanguage},
headers: {
'x-rapidapi-host': 'nlp-translation.p.rapidapi.com',
'x-rapidapi-key': process.env.RAPID_API_KEY
}
};
axios.request(options).then((response) => {
res.json(response.data['translated_text'][toLanguage]);
}).catch((error) => {
console.error(error);
});
})
app.listen(PORT, () => console.log('server is up'))