1、安裝
npm install express --save
2、基本使用
const express = require('express')
// 新建app
const app = express()
app.get('/',function(req,res){
res.send('<h1>hello</h1>')
})
app.get('/data',function(req,res){
res.json({name:'baidu',age:'19'})
})
app.listen(9000,function(){
console.log('8000')
})
3、監聽路由和相應內容,使用nodemon自動重啟
安裝:npm install -g nodemon
使用:sudo node mon server.js
4、其他特性:
- app.get、app.post分別開發get和post接口
- app.use使用模塊
- 代res.send、res.json、res.sendfile相應不同的內容