开始上手express
1 | const express = require('express') |
express会把所有的请求方式都作为方法挂载到app对象中,客户端发送请求并且会执行对应的回调函数1
2
3
4
5
6
7
8const express = require('express')
const app = express()
app.get('/', (req, res, next) => {
res.send("ok")
})
app.listen(8080, () => {
console.log('port created successfully')
})
接收GET数据
1 | const express = require('express') |
接收POST数据
1 | const bodyParser = require(body-parser) |
处理session
1 | const cookieSession = require('cookie-session') |
路由处理
1 | //https://xxx.com/user/1.html |
模板适配
1 | const consolidate = require('consolidate') |
处理文件
1 | app.use(express.static('./dist')) |
处理404
1 | app.use((req, res, next) => { |