-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (38 loc) · 1 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const translate = require('node-google-translate-skidz');
const express = require ('express');
const cors = require('cors')
const path = require('path')
app = express();
app.use(cors())
app.set('view engine', 'ejs')
app.set('views',path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({extended:true}));
app.use(express.json());
const PORT = process.env.PORT || 7000
app.get('/', (req,res)=>{
res.render('index')
})
app.get('/translate/:text/:source/:target', (req,res)=>{
const {text,source, target} = req.params;
translate({
text: text,
source: source,
target: target
}, function(result) {
res.send(result);
});
})
app.get('/translate/:text/', (req,res)=>{
const {text} = req.params;
translate({
text: text,
source: 'auto',
target: 'en'
}, function(result) {
res.send(result);
});
})
app.listen(PORT,()=>{
console.log('Server started successfully')
})