-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 921 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 921 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
const http = require('http');
const axios = require('axios');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer(async (req, res) => {
res.setHeader('Content-Type', 'text/plain');
try {
const url = `https://api.github.com/repos/nodejs/node`;
const { data } = await axios.get(url);
const stargazersCount = data['stargazers_count'];
const forksCount = data['forks_count'];
const openIssuesCount = data['open_issues_count'];
const message = `Stargazers: ${stargazersCount}\nForks: ${forksCount}\nOpen Issues: ${openIssuesCount}`;
res.statusCode = 200;
res.end(message);
} catch (err) {
console.error(err);
res.statusCode = 500;
res.end('Internal error issued.');
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});