iugo / blog

https://iugo.github.io/blog
3 stars 0 forks source link

Node.js 文档阅读笔记 #2

Open iugo opened 7 years ago

iugo commented 7 years ago

Node.js

访问第三方服务需要使用

http.get(options[, callback]) http.request(options[, callback])

前者是后者的特殊化.

如果是 HTTPS, 则使用 https 对象即可.

以上的 callback 有一个参数, 是 http.IncomingMessage 的实例化. 又继承自 stream.Readable.

stream.Readable 有两个重要事件, 一个是 data, 一个是 end.

iugo commented 7 years ago

Node.js 提供的通用对象

Buffer

Node.js 提供的模块

fs

模块名即 File System 的缩写. 实践中常用的就是查看文件, 写入文件.

方法:

readFileSync 同步查看文件内容. writeFileSync 同步写入内容到文件.

http/https

方法:

createServer 作为服务端接收请求. request 作为客户端发起请求.