-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (59 loc) · 2.18 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
60
61
62
63
64
65
66
67
68
69
70
71
const express = require("express");
const path = require("path");
const app = express();
const port = process.env.PORT || 3000;
const bodyParser = require("body-parser");
const axios = require("axios");
require('dotenv').config();
const githubToken = process.env.GITHUB_TOKEN;
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", async (req, res) => {
try {
const packageName = "disbd";
const npmResponse = await axios.get(`https://registry.npmjs.org/${packageName}`);
const packageInfo = npmResponse.data;
const downloadStatsResponse = await axios.get(`https://api.npmjs.org/downloads/point/last-month/${packageName}`);
const downloads = downloadStatsResponse.data.downloads;
const npmPackage = {
name: packageInfo.name,
version: packageInfo["dist-tags"].latest,
description: packageInfo.description,
author: packageInfo.author,
repository: packageInfo.repository,
homepage: packageInfo.homepage,
license: packageInfo.license,
dependencies: packageInfo.versions[packageInfo["dist-tags"].latest].dependencies || [],
downloads: downloads
};
const githubUsername = "Erenkrs";
const githubHeaders = {
Authorization: `Bearer ${githubToken}`
};
const githubResponse = await axios.get(`https://api.github.com/users/${githubUsername}/repos`, { headers: githubHeaders });
const repositories = githubResponse.data.map(repo => {
return {
name: repo.name,
description: repo.description,
url: repo.html_url,
language: repo.language,
stargazers_count: repo.stargazers_count,
forks_count: repo.forks_count,
url: repo.html_url,
description: repo.description
};
});
res.render("index", { npmPackage, repositories });
} catch (error) {
console.error("Error fetching data:", error.message);
res.render("index", { npmPackage: null, repositories: [] });
}
});
app.get("/projects", async (req, res) => {
res.render("proje");
});
app.listen(port, () => {
console.log(`.${port}`);
});