-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (29 loc) · 963 Bytes
/
server.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
import express from "express"
import { dirname } from "path"
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
import { router as articleRouter } from "./routes/articles.js"
let all_articles = [{
id : 1000,
title:"Article 1",
date_created: new Date().toLocaleDateString(),
description:"This is the first article"
}];
const app = express();
const port = 3000;
app.use("/articles",articleRouter)
app.use(express.static("public"))
app.get("/",(req,res)=>{
res.render("articles/index.ejs",{all_articles:all_articles});
});
app.get("/articles/delete/:id",(req,res)=>{
all_articles = all_articles.filter(article => article.id != req.params.id);
res.redirect("/");
})
app.listen(port,()=>{
console.log(`Listening at port ${port}`);
});
function deleteArticleById(id) {
all_articles = all_articles.filter(article => article.id != id);
}
export { all_articles,deleteArticleById}