asp.net网站第一次运行慢,传统文化网站建设,大地资源中文在线观看,建网站要租服务器吗Express内置的中间件
自 Express 4.16.0 版本开始#xff0c;Express 内置了 3 个常用的中间件#xff0c;极大的提高了 Express 项目的开发效率和体验 express.static 快速托管静态资源的内置中间件#xff0c;例如#xff1a; HTML 文件、图片、CSS 样式等#xff08;无…Express内置的中间件
自 Express 4.16.0 版本开始Express 内置了 3 个常用的中间件极大的提高了 Express 项目的开发效率和体验 express.static 快速托管静态资源的内置中间件例如 HTML 文件、图片、CSS 样式等无兼容性 express.json 解析 JSON 格式的请求体数据有兼容性仅在 4.16.0 版本中可用 express.urlencoded 解析 URL-encoded 格式的请求体数据有兼容性仅在 4.16.0 版本中可用
express.json 中间件的使用 express.json() 中间件解析表单中的 JSON 格式的数据
const express require(express)
const app express()// 注意除了错误级别的中间件其他的中间件必须在路由之前进行配置
// 通过 express.json() 这个中间件解析表单中的 JSON 格式的数据
app.use(express.json())app.post(/user, (req, res) {// 在服务器可以使用 req.body 这个属性来接收客户端发送过来的请求体数据// 默认情况下如果不配置解析表单数据中间件则 req.body 默认等于 undefinedconsole.log(req.body)res.send(ok)
})app.listen(3000, () {console.log(running……)
})
express.urlencoded 中间件的使用 express.urlencoded 解析 URL-encoded 格式的请求体数据 const express require(express)
const app express()// 通过 express.urlencoded() 这个中间件来解析表单中的 url-encoded 格式的数据
app.use(express.urlencoded({ extended: false }))app.post(/book, (req, res) {console.log(req.body)res.send(req.body)
})app.listen(3000, () {console.log(running……)
})