-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (35 loc) · 1.75 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const app = express()
const mongoose = require('mongoose') ;
const blogRouts = require('./routes/blogRoutes')
//reg view
app.set('view engine', 'ejs');
//listen for req
//conect to mongodb
const dburi = 'mongodb+srv://skb-test:test12345@test.ancqk.mongodb.net/Nodejs?retryWrites=true&w=majority';
mongoose.connect(dburi, {useNewUrlParser: true, useUnifiedTopology: true})
.then((result) => app.listen(3000))
.catch((err) => console.log(err));
//middleware & static files
app.use(express.static('public'));
app.use(express.urlencoded({extended: true}));
//app.use(morgan('dev'));
app.get('/', (req, res)=> {
res.redirect('/blogs')
/*
const blogs = [
{title: 'blog1', snippet: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non sapien turpis. Ut sit amet ex fermentum, pellentesque metus vel, lacinia ipsum. Aenean sollicitudin rhoncus ultrices. Duis dictum viverra libero ut semper.'},
{title: 'blog2', snippet: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non sapien turpis. Ut sit amet ex fermentum, pellentesque metus vel, lacinia ipsum. Aenean sollicitudin rhoncus ultrices. Duis dictum viverra libero ut semper.'},
{title: 'blog3', snippet: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non sapien turpis. Ut sit amet ex fermentum, pellentesque metus vel, lacinia ipsum. Aenean sollicitudin rhoncus ultrices. Duis dictum viverra libero ut semper.'}
]
res.render('index', {title: 'home ', blogs})*/
});
app.get('/about', (req, res)=> {
res.render('about', {title: 'about '})
});
//blog routs
app.use('/blogs', blogRouts)
//404
app.use((req,res)=>{
res.status(404).render('404', {title: '404'})
})