一、http模塊
const http = require('http') http.createServer(function(req,res) { console.log(req.url) //獲取url里面攜帶的參數 res.writeHead(200,{'Content-type':"text/html;charset='utf-8'"}) //設置響應頭 res.write("<head><meta charset='UTF-8'></head>") //設置編碼,不設置的話就會出現中文亂碼 res.write('this is node js中國加油') //給頁面響應信息 res.end() //響應結束}).listen(8081) //端口號
當我把url改為http://127.0.0.1:8081/aaa時候
console.log(req.url)輸出的內容
【