-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
27 lines (19 loc) · 854 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
const express = require("express");
const articleRouter = require("./routes/articles.js");
const Article = require('./models/articlesmdb.js');
const mongoose = require("mongoose");
const app = express();
const methodOverride = require("method-override");
mongoose.connect("mongodb://localhost/blog" , { useNewUrlParser: true , useUnifiedTopology: true });
//Setting up View Engine.
app.set("view-engine", "ejs");
app.use(methodOverride('_method'))
app.use(express.urlencoded({extended: false}));
app.get("/", async function(req, res){
const articles = await Article.find();
res.render("articles/index.ejs", {articles: articles});
});
app.use("/articles", articleRouter);//I dont know why I put it here, it was in the tutorial.
app.listen("3000", function(){
console.log("Server running at Port 3000");
});