Nodejs爬蟲實戰(一)

1. 搭建本地服務器

  1. const爲ES6新增量,可以理解爲常量,一旦賦值初始化,遍不能修改

  2. 引入http模塊

  3. 創建server,request爲發送的請求,response爲返回的數據

  4. response.write(‘pachong’);屏幕打印

    實質上是node幫我們創建的HTML標籤

  5. response.end();讓響應的代碼結束(不可缺)

    完整代碼

    指定9000端口

     const http = require('http');
     
     http.createServer((request,response)=>{
     
     	response.write('pachong');
     	response.end();
     }).listen(9000);
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章