- All objects that emit events are instances of the
EventEmitter
class. - 运行脚本时处于哪个目录是很重要的context
- require('name'),按照module.paths的顺序查找模块。
- 若require路径没有后缀,会依次尝试.js、.json、.node
- require('name')若只找到name对应的filefolder,会查找其中的pakage.json,取得其中的main属性。若没有pakage.json,则默认为index.js。就这样遍历module.paths。
- process.argv 获取命令行参数
- module wrapper 其中有当前目录和文件名
-
(function(exports, require, module, __filename, __dirname) { // 模块的代码实际上在这里 })
- 许多文件IO函数基于fs.open(path, flag, cb), 可用flag来指定io模式是读还是写等等。
fs.
appendFile() 创建文件或添加内容到文件- fb: File descriptor 大概可以理解为被进程打开文件的id, 数量有限,所以当一个fd不再使用时, 使用fs.close(fd, cd)将他关闭, 以防止too many fd
- generator 和 async 基于 symbol.iterator 实现,所以它们也可以 for of, 通过这样的语法 async function* foo; for await(const foo of foooo()) {}
- child-process 模块 可以执行 terminal 命令
node学习
最新推荐文章于 2023-09-25 18:35:03 发布