-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·36 lines (29 loc) · 909 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
const express = require("express");
const mongoose = require("mongoose");
const Article = require("./models/article");
const articleRouter = require("./routes/articles");
const methodOverride = require("method-override");
const app = express();
const config = require("./config");
db = config.database;
mongoose.connect(
db.url,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
}
);
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: false }));
app.use("/blog/articles", articleRouter);
app.use(methodOverride("_method"));
app.get("/blog", async (req, res) => {
const articles = await Article.find().sort({ createdAt: "desc" });
res.render("articles/index", { articles: articles });
});
app.get("/", (req, res) => {
res.render("apps");
});
app.use("/", express.static(__dirname + "/public"));
app.listen(5000);