-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (44 loc) · 1.41 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
52
53
54
55
56
57
58
59
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const url = require('url');
const fs = require('fs')
const rawdata = fs.readFileSync('./jsdic.json');
const dic = JSON.parse(rawdata);
app.get('/', function (req, res){
res.sendFile(__dirname + "/index.html");
});
app.get('/script.js', function (req, res){
res.sendFile(__dirname + "/script.js");
});
app.get('/style.css', function (req, res){
res.sendFile(__dirname + "/style.css");
});
app.get('/list/', function (req, res){
let ar =[]
console.log('got the get');
//We will get the Url data
const urla = req.url
const q = url.parse(urla, true);
let sub
let sen
//Going to run through the dictionary Array
for(let i=0; i<dic.length; i++) {
//Substract whole String before the numbered Charachter
sub = dic[i].substr(dic[i].length - q.query.num);
//Again substract whole String before the numbered Charachter
sen = q.query.sentence.substr(q.query.sentence.length - q.query.num)
//Check if they are the same
if(sub == sen) {
//Push in the Array
ar.push(dic[i])
}
}
console.log(`result count: ${ar.length}`);
res.setHeader('Content-Type', 'application/json');
//Send the Array
res.send(JSON.stringify(ar))
})
app.listen(port, function () {
console.log(`started on "localhost:${port}"`);
})