From 6ac5f39ddb97553da971df8644dc760b620fbeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=BD=AC=E7=92=90?= <2178814089@qq.com> Date: Sun, 22 Mar 2026 19:26:41 +0800 Subject: [PATCH 1/4] zuoye --- .../20260316\347\254\224\350\256\260.md" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "\345\206\211\345\275\254\347\222\220/20260316\347\254\224\350\256\260.md" diff --git "a/\345\206\211\345\275\254\347\222\220/20260316\347\254\224\350\256\260.md" "b/\345\206\211\345\275\254\347\222\220/20260316\347\254\224\350\256\260.md" new file mode 100644 index 0000000..661d6f2 --- /dev/null +++ "b/\345\206\211\345\275\254\347\222\220/20260316\347\254\224\350\256\260.md" @@ -0,0 +1,22 @@ +```javascript + + +function readFile(filePath) { + // 调用你传的文件路径,否则默认为way + filePath = filePath || './way.json'; + if (fs.existsSync(filePath)) { + let data = fs.readFileSync(filePath, 'utf-8'); + + return JSON.parse(data) || []; + } + return []; +} + +function writeFile(fileContent, filePath) { + filePath = filePath || './way.json'; + let jsonString = JSON.stringify(fileContent); + fs.writeFileSync(filePath, jsonString); +} + +``` + -- Gitee From 89e64a75911e7c7cc829ba2caeda1e2faadd708b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=BD=AC=E7=92=90?= <2178814089@qq.com> Date: Sun, 22 Mar 2026 19:27:14 +0800 Subject: [PATCH 2/4] zuoye --- .../20260318\347\254\224\350\256\260.md" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "\345\206\211\345\275\254\347\222\220/20260318\347\254\224\350\256\260.md" diff --git "a/\345\206\211\345\275\254\347\222\220/20260318\347\254\224\350\256\260.md" "b/\345\206\211\345\275\254\347\222\220/20260318\347\254\224\350\256\260.md" new file mode 100644 index 0000000..30fa95b --- /dev/null +++ "b/\345\206\211\345\275\254\347\222\220/20260318\347\254\224\350\256\260.md" @@ -0,0 +1,52 @@ +# 笔记 + + + +# 作业 + +## 选择题 +- 下面哪个方法可以获取Node.js的版本号? + +- B. process.version + +- Buffer.alloc(10)创建的Buffer,长度是多少字节? + +- A. 10 + +- "你好"的Buffer长度是? + +- C. 6 + +- __dirname表示什么? + +- B. 当前文件所在目录 + +- console.time()和console.timeEnd()的作用是? + +- A. 计时 + +## 简答题 +- 请解释console.log和console.error的区别。 + + - console.log() 用于一般的日志输出,而 console.error() 专门用于错误信息的输出,具有更明显的视觉标识和不同的输出流。 + +- process.argv返回的数组包含哪些内容?请举例说明。 + + - 第一个元素‌:Node.js 可执行文件的路径 ‌ - 第二个元素‌:正在执行的 JavaScript 文件路径 ‌ - 后续元素‌:传递给脚本的命令行参数 + +- Buffer和普通数组有什么区别? + + - Buffer 本质上是字节数组,每个元素都是一个字节 + - 普通数组可以包含任意类型的元素,如整数、字符串等 +- __dirname和process.cwd()有什么区别? + + - __dirname 总是指向当前脚本文件所在的目录,而 process.cwd() 指向的是执行 Node.js 命令时所在的目录 + +- path.join()和path.resolve()有什么区别? + + - path.join() 会忽略前面的路径片段,如果遇到绝对路径参数 + + - path.resolve() 会以绝对路径为基准,从右向左处理直到构建出绝对路径 + + + -- Gitee From d6833c5162a5b60909c407d866f3bb475ab5d2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=BD=AC=E7=92=90?= <2178814089@qq.com> Date: Sun, 22 Mar 2026 19:27:41 +0800 Subject: [PATCH 3/4] zuoye --- .../20260319\347\254\224\350\256\260.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "\345\206\211\345\275\254\347\222\220/20260319\347\254\224\350\256\260.md" diff --git "a/\345\206\211\345\275\254\347\222\220/20260319\347\254\224\350\256\260.md" "b/\345\206\211\345\275\254\347\222\220/20260319\347\254\224\350\256\260.md" new file mode 100644 index 0000000..765d742 --- /dev/null +++ "b/\345\206\211\345\275\254\347\222\220/20260319\347\254\224\350\256\260.md" @@ -0,0 +1,44 @@ +### 查询目录 + +``` +import fs from 'fs' +import {log} from 'console'; + +let dirPath = process.argv[2]; + +browser(dirPath); + +function browser(dir,indent=0){ + if(!fs.existsSync(dir)){ + log('路径不存在,请确认后重试'); + return; + } + + if(!isDirectory(dir)){ + log('路径不存在'); + return; + } + + let prefix = ' '.repeat(indent); + + let arr = fs.readdirSync(dir); + + arr.forEach(item=>{ + let fullPath=dir+'/'+item; + + let fileStat=fs.statSync(fullPath); + if (fileStat.isDirectory()){ + log(prefix+item); + browser(fullPath,ident+1) + }else{ + log(prefix+item) + } + }) +} + +function isDirectory(dir){ + let fileStat=fs.statSync(dir); + return fileStat.isDirectory(); +} +``` + -- Gitee From 57d318c70a0a661dd007b6e26590c26675cfa56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=BD=AC=E7=92=90?= <2178814089@qq.com> Date: Sun, 22 Mar 2026 19:28:13 +0800 Subject: [PATCH 4/4] zuoye --- .../20260320http.md" | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 "\345\206\211\345\275\254\347\222\220/20260320http.md" diff --git "a/\345\206\211\345\275\254\347\222\220/20260320http.md" "b/\345\206\211\345\275\254\347\222\220/20260320http.md" new file mode 100644 index 0000000..b96d0b1 --- /dev/null +++ "b/\345\206\211\345\275\254\347\222\220/20260320http.md" @@ -0,0 +1,110 @@ +# 笔记 + + +## 端口 + +🌐 网页服务 +端口 协议 服务 +80 TCP HTTP +443 TCP HTTPS +8080 TCP HTTP 代理 / 常用备用 Web 端口 +8443 TCP 备用 HTTPS(如 Tomcat) + +📧 邮件服务 +端口 协议 服务 +25 TCP SMTP(邮件发送) +110 TCP POP3(邮件接收) +143 TCP IMAP(邮件接收) +465 TCP SMTPS(SSL/TLS 发送) +587 TCP SMTP 提交(邮件客户端发送) +993 TCP IMAPS(SSL/TLS) +995 TCP POP3S(SSL/TLS) + +📁 文件传输 +端口 协议 服务 +20, 21 TCP FTP(20 数据,21 控制) +22 TCP SSH / SFTP +69 UDP TFTP + +🗄️ 数据库 +端口 协议 数据库 +1433 TCP SQL Server +3306 TCP MySQL / MariaDB +5432 TCP PostgreSQL +6379 TCP Redis +27017 TCP MongoDB +1521 TCP Oracle DB + +🖥️ 远程管理 +端口 协议 服务 +22 TCP SSH +23 TCP Telnet +3389 TCP RDP(远程桌面) +5900+ TCP VNC(默认 5900,后续 +1) + +📡 网络服务 +端口 协议 服务 +53 TCP/UDP DNS +67, 68 UDP DHCP(67 服务端,68 客户端) +123 UDP NTP +161, 162 UDP SNMP +389 TCP/UDP LDAP +636 TCP LDAPS + +🧩 其他常见服务 +端口 协议 服务 +2181 TCP ZooKeeper +2375, 2376 TCP Docker(2375 非加密,2376 TLS) +3000 TCP Node.js / 开发框架默认端口 +5000 TCP Flask / 许多开发服务 +9200, 9300 TCP Elasticsearch +9092 TCP Kafka +11211 TCP Memcached + + + +## 创建web服务器 + +```javascript + +import { log } from 'console'; +// 引入http +import http from 'http' + +// 创建web服务器 +const app = http.createServer((req, res) => { + // 解析文件为html类型,utf-8避免乱码 + res.writeHead(200, { "content-type": "text/html; charset=utf-8"}); + let content = ''; + let path = req.url; + log(req.url); + if(path == '/'){ + content = '我的第一个网站'; + }else if(path == '/about'){ + content = '易遇' + }else if(path == '/aaa'){ + content = '顾时夜' + } + + // let content = rest(req); + // 发送响应内容 + res.end(content); +}); + +// 监听 + +// 3000为端口 +let port = 3000; +app.listen(port, () => { + log(`服务器运行在以下地址,请妥当使用:http://localhost:${port}`) +}); + + + + +``` + + + + + -- Gitee