Error.captureStackTrace
v8提供的功能,用于添加堆栈信息:
Error.captureStackTrace(targetObject[, constructorOpt])
在targetObject中添加一个.stack属性。对该属性进行访问时,将以字符串的形式返回Error.captureStackTrace()语句被调用时的代码位置信息(即:调用栈历史)。
常用于自定义错误类的构造函数中
好处是可以于原生Error区分,.stark第一行的string会变为targetObject:
interfaces = os.networkInterfaces()
获取当前操作系统的网络接口。接口中的 address 字段为可用的网络地址:
lo0,en0…表示当前机器的网络接口,具体解释:https://stackoverflow.com/questions/29958143/what-are-en0-en1-p2p-and-so-on-that-are-displayed-after-executing-ifconfig
重点两个:
en0..X refer to your physical network interfaces. Most new Mac devices will just have en0 - your WiFi. en0 is the first device to start, en1 the second, etc.
lo0 is the ‘loopback’ interface. Otherwise known as localhost, or 127.0.0.1. The others are virtual interfaces.
默认有地址 0.0.0.0,表示所有可用的 ip 地址。
**
https://github.com/http-party/node-portfinder/blob/master/lib/portfinder.js 获取可用port
https://github.com/yarnpkg/yarn/blob/master/src/util/network.js 确认当前是否有网络连接
0.0.0.0 与 127.0.0.1(IPV6为::1)
服务器监听某一端口,host设置为 0.0.0.0 与 127.0.0.1 的区别在于 前者会让局域网内的其他PC通过,本机的 ip 地址 访问本机,而后者只能本机访问本机使用。后者是是本地环回地址。
loopback interface (127.0.0.1 for IPv4 and ::1 for IPv6)