express創建一個應用程序,發送請求
阿新 • • 發佈:2018-05-23
erl back body serve == src spa png run
目錄結構:
1 // 引入模塊 2 var express = require("express"); 3 // 創建一個express應用程序 4 var app = express(); 5 // 靜態文件本地 6 app.use(express.static("public"));//##直接在網頁裏輸入文件名可顯示網頁,例:http://127.0.0.1:9000/text.js## 7 // 發送請求 8 app.get("/",function(req,res){ 9 res.send("Ok") 10 }) 11 app.get("/login.html",function(req,res){12 res.sendFile(`${__dirname}/login.html`) 13 }) 14 // get請求 15 // app.get("/checkuser.html",function(req,res){ 16 // // res.sendFile(`${__dirname}/login.html`) 17 // if(req.query.user=="admin"&&req.query.password=="123"){ 18 // res.send("hello") 19 // } 20 // console.log(req.query)21 // }) 22 app.post("/checkuser.html",function(req,res){ 23 // res.sendFile(`${__dirname}/login.html`) 24 if(req.body.user=="admin"&&req.body.password=="123"){ 25 res.send("hello") 26 } 27 console.log(req.body) 28 }) 29 app.get("*",function(req,res){ 30 res.send(`404`) 31}) 32 // 監聽端口 33 app.listen(9000,"127.0.0.1",function(){ 34 console.log("server is running") 35 })
express創建一個應用程序,發送請求