-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (26 loc) · 766 Bytes
/
index.js
File metadata and controls
29 lines (26 loc) · 766 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
const express = require('express');
const axios = require('axios');
const app = express();
const PORT = process.env.PORT || 8081;
app.get('/', async (req, res) => {
const username = req.query.username || 'myogeshchavan97';
try {
const result = await axios.get(
`https://api.github.com/users/${username}/repos`
);
const repos = result.data
.map((repo) => ({
name: repo.name,
url: repo.html_url,
description: repo.description,
stars: repo.stargazers_count
}))
.sort((a, b) => b.stars - a.stars);
res.send(repos);
} catch (error) {
res.status(400).send('Error while getting list of repositories');
}
});
app.listen(PORT, () => {
console.log(`server started on port ${PORT}`);
});