-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (34 loc) · 880 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
34
35
36
37
38
39
40
41
42
43
const express = require("express");
const app = express();
const router = require("./routes/blogRoute");
const mongoose = require("mongoose");
require("dotenv").config();
const dbURL = process.env.MONGO_URI;
mongoose
.connect(dbURL)
.then((result) => {
app.listen(3000);
})
.catch((err) => {
console.log(err);
});
app.set("view engine", "ejs");
app.set("views", "pages");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.redirect("/blogs");
});
app.get("/about", (req, res) => {
res.render("about", { title: "about" });
});
app.get("/create", (req, res) => {
res.render("create", { title: "CREATE" });
});
app.get("/about-us", (req, res) => {
res.redirect("/about");
});
app.use("/blogs", router);
app.use((req, res) => {
res.status(404).render("404", { title: "404" });
});