-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (26 loc) · 949 Bytes
/
app.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
const { error } = require("console");
const express = require("express");
const { rmSync } = require("fs");
const mongoose = require("mongoose");
const app = express();
const db =
"mongodb+srv://Alper:g4nAWgCNRuAAqFya@nodeblog.w7eaite.mongodb.net/test";
const { render } = require("ejs");
const blogsRoute = require("./routes/blogsRoute");
const aboutRoute = require("./routes/aboutRoute");
mongoose
.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
.then((result) => app.listen("3000"), console.log("Successfully connected"))
.catch((error) => console.log(error));
app.set("view engine", "ejs");
app.set("views", "html");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.redirect("/blogs");
});
app.use("/about", aboutRoute);
app.use("/blogs", blogsRoute);
app.use((req, res) => {
res.status(404).render("404", { title: "404: Not found" });
});