node.js

    xiaoxiao2023-10-19  151

    一.node.js Node.js内置了很多的模块 fs(文件系统) path( 磁盘路径 ) http( 通信 ) 使用; 1. 导入 const 变量名称 = require(‘模块名称’) 2. 使用模块的api

    二.Node.js中第三方模块如何使用?https://www.npmjs.com/

    安装 初始化生成 package.json安装对应的包 举例: npm i request -g/-D/-S 名词说明: -g -global 全局 -D / --save-dev 开发环境 -S / -save 生产环境b 导入 request 用来做数据请求的使用 去看文档(www.npmjs.com)

    三.Node.js自定义模块步骤:

    定义 对象 函数 字符串 。。。导出 module.exports || exports使用 const 变量名称 = require(‘模块名称’)扩展 需求: 安全性考虑 封装一下下 {} 操作流程 1.创建一个文件夹 2.创建pageage.json Yarn init / npm init /cnpm init 快速创建 npm init -y / yarn init -y /cnpm init -y 3.注册npm仓库 www.npmjs.com注册一个账号 命令行执行 npm adduser(必须确保你当前的源是npmjs,使用nrm来切换源) 4.上传包 npm publish 注意: 1.npm源切换 nrm. npm i nrm -g 2.注意:npm账号需要邮箱认证``

    四.http总结 1. 使用Node.js实现一个web服务器 2. Node.js中模块的api很多时候可以连缀(链式调用) 3. http 1. createServer 创建一个web静态服务器 2. listen 是用来监听当前服务器 3. 名词解释 1. port 端口 2. hostname: 域名 3. request 请求, Node.js请求谁 4. response 回应] 5. data 数据 6. encoding; 编码方式 utf8 默认utf8 4. write(data,encoding) 给前台发送一个内容 5. end() 发送已经结束了

    6. 坑 中文乱码问题 解决方案一: response.writeHead(200,{ 'Content-Type': 'text/html; charset=UTF-8' }) 解决方案2: response.write('<head> <meta charset="UTF-8"> </head>')

    五.url url: 用来做 浏览器 地址 解析的 api: parse : String --> Object format: Object —> String resolve: url拼接

    完整的url构成: https: // www.web-yyb.top: 8080 / vue / index.html ? a=1&b=2#a=10

    协议: https 域名: www.web-yyb.top 端口: 8080 路径: www.web-yyb.top: 8080 / vue / index.html 查找字符串: a=1&b=2 哈希: #a=10

    六.querystring qs: 干什么: 进行string 和 object 的格式 功能: 类似JSON.parse || JSON.stringify

    api: parse stringify Object ---> String escape unescape 名词 encoding 编码 unencoding 解码 escape 中文编码 unescape 中文解码

    七.http-get get方法 http 格式: http.get(url,callback)

    on 原生js如何触发事件 DOM.onclick = function(){} 名词解释: DOM: 节点 on: 添加事件的形式 click: 事件类型 function(){}: 事件处理程序 chunk: 分片 try {} catch{} 高级编程 错误信息捕获
    最新回复(0)