乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Node.js基礎(chǔ)學(xué)習(xí)(1)

       路人甲Java 2021-09-08
       1 //用于創(chuàng)建網(wǎng)站服務(wù)器的模塊
       2 const http = require('http');
       3 //app對(duì)象就是網(wǎng)站服務(wù)器對(duì)象
       4 const app = http.createServer();
       5 // node內(nèi)置對(duì)象 用于處理URL地址
       6 const url = require('url');
       7 
       8 //事件(請(qǐng)求)處理函數(shù),當(dāng)客戶端有請(qǐng)求的時(shí)候
       9 //request請(qǐng)求,response響應(yīng)
      10 app.on('request',(req,res)=>{
      11     //獲取請(qǐng)求的方式
      12     //req.method
      13     // console.log(req.method);    
      14 
      15     //獲取請(qǐng)求的地址
      16     //req.url
      17     console.log(req.url);
      18     //第一個(gè)參數(shù)要解析的url地址,第二個(gè)參數(shù)為true時(shí) 解析當(dāng)前請(qǐng)求地址已對(duì)象的形式返回 
      19     // console.log(url.parse(req.url,true).query);
      20 
      21     // req.headers
      22     // console.log(req.headers['accept']); 
      23 
      24     // 用解構(gòu)賦值的形式拿到當(dāng)前url里面的query,pathname
      25     let {query,pathname}=url.parse(req.url,true);
      26     console.log(query.name);
      27     console.log(query.age);
      28 
      29 
      30     res.writeHead(200, {
      31         'content-type': 'text/html;charset=utf8'
      32     });
      33     
      34    
      35     if(pathname=='/index' || pathname=='/' ){
      36         res.end('<h2>welcome to homepage</h2>');
      37     }else if(pathname=='/list'){
      38         res.end('welcome to listpage');
      39     }else{
      40         res.end('404');
      41     }
      42     
      43 
      44     // if(req.method== 'POST'){
      45     //     res.end('post');
      46     // }else if (req.method== 'GET'){
      47     //     res.end('get');
      48     // }
      49     //響應(yīng)內(nèi)容
      50     // res.end('<h2>hello user</h2>')
      51 
      52 });
      53 
      54 //監(jiān)聽端口
      55 app.listen(3000);
      56 console.log('網(wǎng)站服務(wù)啟動(dòng)成功!')
      57 
      58 // 訪問本地 localhost:3000

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多