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相应不同的内容
网友评论