forked from CSI-KJSCE/csi_superhero_fanpage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (25 loc) · 923 Bytes
/
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
const express = require('express');
const cors = require('cors');
const fs = require('fs');
const path = require('path')
const app = express();
app.use(express.json());
app.use(cors());
app.get('/',async(req,res) =>{
try {
var json_data =[];
const jsonsInDir = fs.readdirSync('./data').filter(file => path.extname(file) === '.json');
jsonsInDir.forEach(file => {
const fileData = fs.readFileSync(path.join('./data', file));
const json = JSON.parse(fileData.toString());
json_data.push(json);
console.log(json)
});
res.status(200).send(json_data);
} catch (error) {
console.log(error);
res.status(203).send("Error");
}
})
const PORT = process.env.PORT || 8080;
const server = app.listen(PORT, () => console.log("App is listening on url http://localhost:" + PORT))