-
Notifications
You must be signed in to change notification settings - Fork 35
/
getNews.js
36 lines (25 loc) · 855 Bytes
/
getNews.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
const fs = require('fs');
const {Router} = require('express');
const router = Router();
// Interval so the news update themselves
setInterval(()=>{
try {
//We get our news title from here
const readFile = fs.readFileSync('./public/js/app/members/news.json',
{encoding:'utf8', flag:'r'});
const data = JSON.parse(readFile);
let articleTitle = [];
//we push the title names into an array so we can loop through the different routes\
for (let i = 0; i < data.length; i++) {
let title = data[i].title.replace(/ /g, '-');
articleTitle.push(title);
}
//we create a get route for each article found
articleTitle.forEach(page => router.get(`/news/${page}`, (req, res) => {
res.render('newsArticle');
}));
} catch (e) {
console.log('error on flash!')
}
},1000 * 60 * 5);
module.exports = router;