天天看點

2:建立WEB伺服器

代碼

// 引用系統子產品
 const http = require('http');
  // 建立web伺服器
 const app = http.createServer();
  // 當用戶端發送請求的時候
 app.on('request', (req, res) => {
        //  響應
       res.end('<h1>hi, user</h1>');
 });
  // 監聽3000端口
 app.listen(3000);
 console.log('伺服器已啟動,監聽3000端口,請通路 localhost:3000')      
PS D:\nodecode\server> node .\app.js
網站伺服器啟動成功       
2:建立WEB伺服器

繼續閱讀