随笔分类 -  nodejs学习笔记

摘要:API Application Programming Interface: a piece of software that can be used by another piece of software, in order to allow application to talk to eac 阅读全文
posted @ 2022-06-22 01:16 kihyun 阅读(28) 评论(0) 推荐(0) 编辑
摘要:设置ESLint 安装组件 npm i eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-config-airbnb eslint-plugin-node eslint-plugin-import eslint- 阅读全文
posted @ 2022-06-22 01:12 kihyun 阅读(64) 评论(0) 推荐(0) 编辑
摘要:中间件 在node执行的过程中,在请求和应答的中间会有很多中间处理不同东西的组件,这样的组件叫做中间件。中间件的执行过程是:请求发送-第一个中间件接收-第一个中间件应答-第一个中间件请求-第二个中间件接收-第二个中间件应答-第二个中间件请求-最终应答。 具体使用: app.use((req, res 阅读全文
posted @ 2022-06-22 01:10 kihyun 阅读(48) 评论(0) 推荐(0) 编辑
摘要:建立server 创建express对象 const express = require('express'); const app = express(); 监听端口 const port = 3000; app.listen(port, () => { console.log(`App runn 阅读全文
posted @ 2022-06-22 01:06 kihyun 阅读(108) 评论(0) 推荐(0) 编辑
摘要:1. 请求的运作过程 2. 前端和后端的定义 前端: font-end is about everything that happens in the web browser. It is about designing and building the final website that's g 阅读全文
posted @ 2022-06-18 03:04 kihyun 阅读(34) 评论(0) 推荐(0) 编辑
摘要:事件驱动模型,观察者模式 同一个事件,多个监听器 const EventEmitter = require("events"); const myEmitter = new EventEmitter(); // 这里是两个观察者,观察对应的对象,等待对象做出动作 myEmitter.on("newS 阅读全文
posted @ 2022-06-18 03:00 kihyun 阅读(23) 评论(0) 推荐(0) 编辑
摘要:1. 事件循环的概念: event loop is all the application code that is inside callback functions(non-top-top-level code) 2. 事件循环的步骤 强调的是两个另外的任务队列,他们执行的时机在每个主任务执行完 阅读全文
posted @ 2022-06-18 02:58 kihyun 阅读(111) 评论(0) 推荐(0) 编辑
摘要:stream stream的类型有四种,常见的是前面两种 三段逐渐升级的返回读取文件的代码 fs读取写入 const fs = require("fs"); const server = require("http").createServer(); server.on("request", (re 阅读全文
posted @ 2022-06-18 02:52 kihyun 阅读(27) 评论(0) 推荐(0) 编辑
摘要:Web API 我们要写一个api去读取一个json文件里面的内容 这里是最初的版本 const server = http.createServer((req, res) => { const pathName = req.url; if (pathName "/api") { // __dirn 阅读全文
posted @ 2022-06-18 02:48 kihyun 阅读(59) 评论(0) 推荐(0) 编辑
摘要:导入http模块 const http = require('http'); 创建server const server = http.createServer((req, res) => { res.end("Hello form the server!"); }); 开启server serve 阅读全文
posted @ 2022-06-18 02:46 kihyun 阅读(50) 评论(0) 推荐(0) 编辑
摘要:fs模块 读取数据 同步读取数据-> readFileSync 参数(path,buffer) const fs = require('fs'); const textIn = fs.readFileSync('./txt/input.txt','utf-8'); console.log(textI 阅读全文
posted @ 2022-06-18 02:45 kihyun 阅读(43) 评论(0) 推荐(0) 编辑
摘要:promise & async/await promise 为什么出现promise? 回调地狱 promise的三个状态 pending fullfilled rejected 真正解决回调地狱 promise里面不嵌套then 每一个都返回一个promise再then const readFil 阅读全文
posted @ 2022-06-18 02:44 kihyun 阅读(25) 评论(0) 推荐(0) 编辑
摘要:导入模块 导入模块的步骤 导入模块分为五个步骤 解析导入的代码 包装 执行 返回模块 缓存,模块在第一次加载的时候就缓存下来了,第二次请求相同的模块的时候不会重新请求 导入模块的方法 module.exports test-module-1.js两种方式 ①写完类再导出 class Calculat 阅读全文
posted @ 2022-06-18 02:42 kihyun 阅读(63) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示