1、global对象,是Node.js中的全局命名空间,任何全局变量、函数或对象都是该对象的属性值。
2、setTimeout函数 与 clearTimeout函数
setTimeout(cb,ms,[arg],[...]) //cb:需要执行的回调函数 //ms:一个整数,指定经过多少毫秒后执行该回调函数 //arg:可选,需要向回调函数中传入的参数
3、setInterval函数 与 clearInterval函数
setInteval(cb,ms,[arg],[...]) //cb:需要执行的回调函数 //ms:一个整数,指定经过多少毫秒后执行该回调函数 //arg:可选,需要向回调函数中传入的参数
4、定时器对象的unref() 与 ref()
unref()取消setTimeout函数 或 setInterval函数中指定的回调函数的调用
使用unref()取消后,可以使用ref()恢复回调函数的调用
5、require函数:参数为完整路径的模块文件名,或直接是模块名
require.main:用于检测一个模块是否为应用程序中的主模块(写在被检测的模块文件内部)
if(module === require.main){ console.log('true') }
对于相同模块的多次引用不会引起模块内代码的多次执行
require.resolve:查询某个模块文件的带有完整绝对路径的文件名。不过并不会加载该模块
require.resolve('./testModule.js')
require.cache对象:代表缓存了所有已被加载模块的缓存区
console.log(require.cache)
可以通过争名来访问某个模块
require.cache['模块文件名']
_filename:获取当前模块文件带有完整绝对路径的文件名
_dirname:获取当前模块文件所在目录的完整绝对路径