灵心如玉,守一生无惧|

SadicZhou

园龄:3年2个月粉丝:7关注:4

node4_01创建基本的web服务器

1
2
3
4
5
6
7
8
9
10
11
12
//1.导入http模块
const http = require("http")
//2.创建web服务器实例
const server = http.createServer()
//3.为服务器实例绑定request实例,监听客户端的请求
server.on('request',function(req,res){
     console.log('Someone visit our web server')
})
//4.启动服务器
server.listen(8080,function(){
    console.log('server running at http://127.0.0.1:8080')
})

  

 

 

  • Node中提供了http模块,其中封装了高效的http服务器和http客户端
  • http.Server是一个基于事件的http服务器,内部是由c++实现的,接口是由JavaScript封装
  • http.request是一个http客户端工具。 用户向服务器发送数据。

本文作者:SadicZhou

本文链接:https://www.cnblogs.com/SadicZhou/p/16847264.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   SadicZhou  阅读(19)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 尚好的青春 孙燕姿
  2. 2 孙燕姿
  3. 3 克卜勒 孙燕姿
- 孙燕姿
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.