-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (27 loc) · 1.01 KB
/
index.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
const express = require('express')
const path=require('path')
const methodOverride = require('method-override')
const bodyParser=require('body-parser')
const morgan=require('morgan')
const { connection, mysql } = require('./models/connection.js')
const blogrouter=require('./routes/blogroutes.js')
const commentrouter=require('./routes/commentroutes.js')
const PORT=process.env.PORT || 3000
const app = express()
require('dotenv').config()
app.use(morgan('dev'))
app.set('view engine','ejs')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(methodOverride('_method'))
app.use(express.static(path.join(__dirname,"public")))
app.use('/uploads',express.static(path.join(__dirname,"uploads")))
app.get('/',(req,res)=>{
connection.query('SELECT * FROM blog',(err,results,fields)=>{
if(err) throw err;
res.render('index.ejs',{"results":results})
})
})
app.use('/blog',blogrouter)
app.use('/comment',commentrouter)
app.listen(PORT, () => {console.log(`listening at ${PORT}`) })