摘要: 示例:初始化目录结构 /** * 文件操作案例(初始化目录结构) */ //文件路径 const path = require("path"); const fs = require("fs"); let root = __dirname; let fileContent = ` <!DOCTYPE 阅读全文
posted @ 2020-09-28 17:39 mrtransition 阅读(138) 评论(0) 推荐(0)
摘要: 目录操作 创建目录 读取目录 删除目录 /* 目录操作 1、创建目录 fs.mkdir(path[, options], callback) fs.mkdirSync(path[, options]) 2、读取目录 fs.readdir(path[, options], callback) fs.r 阅读全文
posted @ 2020-09-28 17:37 mrtransition 阅读(289) 评论(0) 推荐(0)
摘要: 大文件操作(文件流) /* 大文件操作(流式操作) //内存开销会比较小,速度更快 fs.createReadStream(path[, options]) fs.createWriteStream(path[, options]) */ const path = require('path'); 阅读全文
posted @ 2020-09-28 17:15 mrtransition 阅读(345) 评论(0) 推荐(0)
摘要: 文件fs const fs = require('fs'); 读取 readFile /* 读取文件操作 readFile readFileSync */ const fs = require('fs'); const path = require('path'); let strpath = pa 阅读全文
posted @ 2020-09-28 16:52 mrtransition 阅读(188) 评论(0) 推荐(0)
摘要: /* * 文件操作 fs * 文件信息获取 * */ const fs = require('fs'); //异步操作 console.log(1); fs.stat('./03.js',(err,stats) =>{ if(err){ console.log(err); return; } if( 阅读全文
posted @ 2020-09-28 15:13 mrtransition 阅读(273) 评论(0) 推荐(0)
摘要: 事件模型 异步I/O 1. 文件操作 2. 网络操作 在浏览器中也存在异步操作 1. 定时任务 2. 事件处理 3. Ajax回调处理 js的运行是单线程的,引入事件队列机制解决阻塞问题 Node.js中的事件模型与浏览器中的事件模型类似:单线程+事件队列 Node.js中异步执行的任务: 1. 文 阅读全文
posted @ 2020-09-28 14:37 mrtransition 阅读(118) 评论(0) 推荐(0)
摘要: 路径Path 引入 /* * 路径模块 path * */ const path = require('path'); //获取路径最后部分 // console.log(path.basename('/foo/bar/baz/asdf/quux.html')); // console.log(pa 阅读全文
posted @ 2020-09-28 14:07 mrtransition 阅读(158) 评论(0) 推荐(0)