@Tricksyz/

nordvpn-server-list

Nodejs

No description

fork
loading
Files
  • index.js
  • LICENSE
  • nordvpn-server-list.js
  • package-lock.json
  • package.json
  • README.md
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
const https = require('https');

https.get('https://zwyr157wwiu6eior.com/server', (response) => {
    let body = '';

    response.on('data', function (d) {
        body += d;
    });

    response.on('end', function () {

        let serverList = [];
        let parsed = '';

        try {
            parsed = JSON.parse(body);
            serverList = getServers(parsed);
        } catch (e) {
            console.error("Error! Servers list should be in JSON format but it isn't");
        }

        serverList.forEach(function (server) {
            process.stdout.write(server + "\n");
        }, this);

    });

}).on('error', (e) => {
    console.error(e);
});

function getServers(data) {
    let servers = [];

    data.forEach(function (element) {

        if (element.domain !== '') {
            servers.push(element.domain);
        }

    }, this);

    servers.sort();

    return servers;
}
node v10.16.0