let http = require('http')
let fs = require('fs')
http.createServer((req,res)=>{
console.log("我来了");
console.log(req.url);
res.end('index');
fs.readFile(`${req.url}`,(err,data)=>{
if(err){
console.log(err)
res.writeHead(404)
res.end('404 not found')
}else{
res.end('demo1');
}
})
}).listen(8887)

node11-node的 http模块_前端

 

node11-node的 http模块_前端_02