微信小程序:(安裝node.js)命令窗口中必須做的幾步
來源:我的學(xué)習(xí)筆記




我舉個(gè)例子(先在本文件夾下面創(chuàng)建一個(gè)TXT文檔,編寫下面的代碼完成后改格式為index.js):
const express = require('express')? ?//加載express模塊
const bodyParser = require('body-parser')? ?//加載解析客戶端發(fā)送的實(shí)體內(nèi)容
const app = express()? //創(chuàng)建實(shí)例
app.use(bodyParser.json())? //使用json格式
//處理POST請(qǐng)求
app.post('/',(req,res)=>{
console.log(req.body)
res.json(req.body)? //響應(yīng)回瀏覽器
})
? ?// 表單數(shù)據(jù)綁定1:data中保存表單的默認(rèn)數(shù)據(jù)
? var data={
? ? name:'張三',
? ? gender:[
? ? ? {name:'男',value:'0',checked:true},
? ? ? {name:'女',value:'1',checked:false}
? ? ],
? ? skills:[
? ? ? {name:'HTML',value:'html',checked:true},
? ? ? {name:'CSS',value:'css',checked:true},
? ? ? {name:'JavaScript',value:'js',checked:false},
? ? ? {name:'Photoshop',value:'ps',checked:false}
? ? ],
? ? opinion:'測(cè)試'
?}
?
app.get('/',(req,res) => {
? res.json(data)
})
//監(jiān)聽3000端口
app.listen(3000,()=>{
console.log('server running at http://127.0.0.1:3000')? //監(jiān)聽成功輸出信息
})