-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (29 loc) · 800 Bytes
/
app.js
File metadata and controls
36 lines (29 loc) · 800 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
34
35
36
const express=require('express')
let router=require('./router')
const bodyParser = require('body-parser')
const path = require('path')
const app=express()
//公开资源
app.use(express.static('public'))
app.use(express.static('node_modules'))
//模板引擎
app.engine('html',require('express-art-template'))
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//把路由容器挂载到app服务中
app.use(router)
app.use(function (req,res,next) {
res.send('404')
})
//配置错误处理中间件
app.use(function (err,req,res,next) {
res.status(500).json({
err_code:500,
message:err.message
})
})
app.listen(3000,function () {
console.log('app is running!')
})