首页 > Web开发 > 详细

4 —— node —— 启动一个 http 服务器

时间:2019-05-26 13:09:38      阅读:125      评论:0      收藏:0      [点我收藏+]
const http = require(‘http‘);

const server = http.createServer();

  // 绑定客户端请求事件
  // on => 绑定事件
  // request => 请求事件
  // 为 nodejs 系统调用 (因为是nodejs调用)
  // 给server对象绑定request事件
 
  server.on(‘request‘,function(req,res){
 
 
  // 前台请求的方式
  if(req.method == ‘GET‘){
    console.log(‘GET请求‘)
  }

  if(req.method == ‘POST‘){
    console.log(‘POST请求‘)
  }
 
  res.end()
});

server.listen(1234,()=>{
console.log(‘this server is runing on 1234‘)
});

// 必须加上分号,上面的也是。也就是之前bug出现的原因

4 —— node —— 启动一个 http 服务器

原文:https://www.cnblogs.com/500m/p/10925684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!