-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (26 loc) · 1018 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
28
29
30
31
32
33
34
35
36
37
38
const exphbs = require('express-handlebars')
const express = require('express')
const app = express()
const port = 3000
const hostname = '127.0.0.1'
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const FileUpload = require('./node_modules/express-fileupload/lib/index')
const generateDate = require('./helpers/generateDate').generateDate
mongoose.connect('mongodb://127.0.0.1/nodeblog')
app.use(FileUpload())
app.use(express.static('public'))//middleware
app.engine('handlebars', exphbs.engine({helpers:{generateDate:generateDate}}))
app.set('view engine', 'handlebars')
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
const main = require('./routes/main')
const posts = require('./routes/posts')
const users = require('./routes/users')
app.use('/',main)
app.use('/posts',posts)
app.use('/users',users)
app.listen(port, hostname, () => {
console.log(`Example app listening on port http://${hostname}:${port}`)
})