From fb51ff20fd4a48dac732f2acee752da4d91abfbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=BE=BD=E6=98=9F?= <210450755@qq.com> Date: Sun, 22 Mar 2026 11:21:49 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈羽星 <210450755@qq.com> --- .../20260316-\345\233\236\351\241\276.md" | 67 +++++++++++++++++++ ...05\347\275\256\346\250\241\345\235\227.md" | 24 +++++++ ...73\347\273\237\346\250\241\345\235\227.md" | 11 +++ .../20260320-http\346\250\241\345\235\227.md" | 22 ++++++ 4 files changed, 124 insertions(+) create mode 100644 "\351\231\210\347\276\275\346\230\237/20260316-\345\233\236\351\241\276.md" create mode 100644 "\351\231\210\347\276\275\346\230\237/20260318-\345\206\205\347\275\256\346\250\241\345\235\227.md" create mode 100644 "\351\231\210\347\276\275\346\230\237/20260319-\347\263\273\347\273\237\346\250\241\345\235\227.md" create mode 100644 "\351\231\210\347\276\275\346\230\237/20260320-http\346\250\241\345\235\227.md" diff --git "a/\351\231\210\347\276\275\346\230\237/20260316-\345\233\236\351\241\276.md" "b/\351\231\210\347\276\275\346\230\237/20260316-\345\233\236\351\241\276.md" new file mode 100644 index 00000000..e4d0784d --- /dev/null +++ "b/\351\231\210\347\276\275\346\230\237/20260316-\345\233\236\351\241\276.md" @@ -0,0 +1,67 @@ +# 课堂笔记 + +# 练习 + +import fs from "fs"; + + + +const command = process.argv[2] + +const params = process.argv[3] + + + +if (command == "list") { + + console.log("list"); + +} if (command == "add") { + + console.log("添加数据"); + + let arr = readFile(); + + arr.push({ + +​ amount: params * 1, + +​ type: 'input', + +​ timestamp: new Date() + + }) + + write(arr); + + + + + +} + +function readFile(pathFile) { + + pathFile = pathFile || './data.json'; + + if (fs.existsSync(pathFile)) { + +​ let data = fs.readFileSync(pathFile, "utf-8"); + +​ return JSON.parse(data); + + } + + return []; + +} + +function write(fileContent, filePath) { + + filePath = filePath || './data.json'; + + let jsonString = JSON.stringify(fileContent); + + fs.writeFileSync(filePath, jsonString); + +} \ No newline at end of file diff --git "a/\351\231\210\347\276\275\346\230\237/20260318-\345\206\205\347\275\256\346\250\241\345\235\227.md" "b/\351\231\210\347\276\275\346\230\237/20260318-\345\206\205\347\275\256\346\250\241\345\235\227.md" new file mode 100644 index 00000000..b2910cee --- /dev/null +++ "b/\351\231\210\347\276\275\346\230\237/20260318-\345\206\205\347\275\256\346\250\241\345\235\227.md" @@ -0,0 +1,24 @@ +# 课堂笔记 + +``` +// 1. console模块 - 多种输出方式 +console.log('普通信息'); +console.info('提示信息'); +console.warn('警告信息'); +console.error('错误信息'); +console.table([{name: '张三', age: 20}]); + +// 2. process模块 - 获取进程信息 +console.log('Node版本:', process.version); +console.log('平台:', process.platform); +console.log('当前目录:', process.cwd()); + +// 3. Buffer模块 - 处理二进制 +const buf = Buffer.from('Hello'); +console.log(buf); // + +// 4. path模块 - 路径处理 +const path = require('path'); +console.log(__dirname); +console.log(__filename); +``` diff --git "a/\351\231\210\347\276\275\346\230\237/20260319-\347\263\273\347\273\237\346\250\241\345\235\227.md" "b/\351\231\210\347\276\275\346\230\237/20260319-\347\263\273\347\273\237\346\250\241\345\235\227.md" new file mode 100644 index 00000000..1589008f --- /dev/null +++ "b/\351\231\210\347\276\275\346\230\237/20260319-\347\263\273\347\273\237\346\250\241\345\235\227.md" @@ -0,0 +1,11 @@ +# 课堂笔记 + +### 实现简单的文件浏览器 + +方法:statSync()识别文件 / 文件夹的「状态 / 属性信息」可以识别是文件夹还是文件 + +isDirectory()识别是否是文件 + +readdirSync()是把查找路径下的文件组成一个数组 + +function bro(dir, i = 0) 第二个参数为空格 使得文件夹和文件件更加有层次感 \ No newline at end of file diff --git "a/\351\231\210\347\276\275\346\230\237/20260320-http\346\250\241\345\235\227.md" "b/\351\231\210\347\276\275\346\230\237/20260320-http\346\250\241\345\235\227.md" new file mode 100644 index 00000000..b8920ff4 --- /dev/null +++ "b/\351\231\210\347\276\275\346\230\237/20260320-http\346\250\241\345\235\227.md" @@ -0,0 +1,22 @@ +# 课堂笔记 + +# 创建web服务器 + +先引入http 模块 + +createServer()创建服务器方法 里面承载回调函数 + +app.listen(3000); 监听服务器的端口为3000 + + res.writeHead(200,{"content-type":"text/html; charset=utf8"}) 响应头方法 200是返回类型 404这样 + + {"content-type":"text/html; charset=utf8"} 对象是 设立格式为utf8 + +\- 如果写 `text/plain`,浏览器会把返回的内容当纯文本(即使是 HTML 标签也不会解析); + +\- 如果写 `application/json`,则表示返回的是 JSON 数据(接口开发常用); + + + + + -- Gitee