express

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相應不同的內容
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容