-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (24 loc) · 991 Bytes
/
server.js
File metadata and controls
33 lines (24 loc) · 991 Bytes
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 express = require('express')
const app = express()
const mongoose = require('mongoose')
const methodOverride = require('method-override')
//server made with http
const server = require("http").Server(app);
const Article = require('./models/articleSchema')
const route = require('./routes/articleRoutes')
app.set('view engine', 'ejs')
app.use(methodOverride('_method'))
app.use(express.urlencoded ({ extended : false}))
mongoose.connect('mongodb+srv://Aishani:l9kWQXf3j7S9l0yg@cluster.gugjm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', {
useNewUrlParser : true, useUnifiedTopology : true, useCreateIndex : true
}).then(() => {
console.log("database connected");
}).catch((err) => {
console.log(`No connection: ${err}`);
});
app.get('/', async(req,res) =>{
const articles = await Article.find().sort({ date : 'desc'})
res.render('articles/landing', {articles : articles})
})
app.use('/articles',route)
server.listen(process.env.PORT || 3000)