forked from zeel-codder/Recursion-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (42 loc) · 1.23 KB
/
server.js
File metadata and controls
53 lines (42 loc) · 1.23 KB
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
const express = require('express')
const app = express()
const fs = require('fs')
const matter = require('gray-matter');
// app.use(express.static(''))
// app.use(express.urlencoded())
// app.engine('html', require('ejs').renderFile)
// app.set('view engine', 'html');
app.use('/public', express.static(__dirname + '/static'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/template/index.html')
});
app.get('/list', (req, res) => {
try {
const list = GetList()
res.send(JSON.stringify(list));
} catch (error) {
console.log("Error in GetList Function\n",error);
}
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
function GetList() {
let ct=0;
try {
const list = []
let filesList = fs.readdirSync(__dirname + '/Code');
filesList.forEach(file => {
const data = fs.readFileSync(__dirname + '/Code/' + file);
const dataForm = matter(data);
const toAdd = { "data": dataForm.data, "content": dataForm.content }
list.push(toAdd);
ct++;
})
return list;
}
catch (e) {
console.log("Error in File No(0-based)",ct)
}
}