Node API查找

情景说明:想要查找http模块中创建的server实例在监听时的回调函数是什么对象,对象拥有哪些属性和方法。
比如:下面例子中 请求对象有哪些属性和方法呢?

var http = require('http')
var fs = require('fs')

var server = http.createServer()

server.on('request',function(req,res){
	var url = req.url
        //查看请求对象有哪些属性和方法
	console.log(req.httpVersion)

})

server.listen(3000,function(){
	console.log('server is running...')
})

步骤:

  1. 在官网中找到http模块,然后搜索http.createServer
    https://nodejs.org/dist/latest-v16.x/docs/api/http.html#http_http_createserver_options_requestlistener
  2. 查看返回值
  3. 找到server实例的request事件说明

  4. 查看请求对象具体的数据类型
  5. 验证对象实例数据类型
console.log(req instanceof http.IncomingMessage)
原文地址:https://www.cnblogs.com/it774274680/p/14755742.html