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 0000000000000000000000000000000000000000..e4d0784d1437212caf37ec1c4281663b8922b0b0 --- /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 0000000000000000000000000000000000000000..b2910cee27229291c461cd6b660de525033b18f2 --- /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 0000000000000000000000000000000000000000..1589008fc9387d102c5477b00e5f5914d9e87a98 --- /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 0000000000000000000000000000000000000000..b8920ff442d4efa8298983acfa8b6545bcbe30d2 --- /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 数据(接口开发常用); + + + + +