-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
27 lines (20 loc) · 892 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
const express = require("express");
const mongoose = require("mongoose");
const connectDB = require('./db/connection');
const articlerouter = require('./routes/articles');
const Article = require("./models/article");
const methodOverride = require('method-override');
const app = express();
connectDB();
app.set('view engine', 'ejs');
// .urlencoded(), helps accessing all the parameters from new articles forms, inside articles router, in (req.body.)
app.use(express.urlencoded({extended: false}));
app.use(methodOverride('_method'));
app.get('/', async(req, res)=>{
const articles = await Article.find().sort({createdAt: 'desc'});
res.render('articles/index', {articles:articles});
})
// if this below is above urlencoder, we'll get an error, saying cant read title property of undefined
// meaning req.body == undefined
app.use('/articles',articlerouter);
app.listen(5000);