标签: Node.js
34 个内容
笔记(32)
Hono作为极简Web框架,其优雅停机依赖Runtime(如Node.js、Bun)。**关键问题**:Runtime差异及异步任务卡死。**方案**:Node.js用@hono/node-server的server.close()监听SIGTERM;Bun用server.stop();追踪activeRequests轮询等待任务完成。Serverless环境无需处理。
本文探讨Node.js中安全注入DSL模板变量的核心挑战,提供Handlebars(文本替换)、Jexl(逻辑表达式)和json-rules-engine(结构化规则)等方案。建议封装DSLEngine预编译模板,避免eval()注入风险,优化性能并处理类型转换。(148字符)
浏览器通常自动解压服务器返回的 GZIP 数据。若需手动解压,前端可用 `pako` 库,Node.js 可用 `zlib` 模块。浏览器 `fetch` 获取的数据默认解压。
该文探讨Node.js同步/异步文件读取性能差异及阻塞问题。背景:`fs.promises.readFile`比`fs.readFile`慢。问题:同步读取阻塞事件循环,影响并发。方案:避免同步I/O,采用异步方式,如`fs.promises.readFile`,提升服务器并发性能。
本文总结了Node.js开发中的常见问题与技巧。包括:使用`process.hrtime()`进行高精度计时,利用`async_hooks`跟踪异步资源生命周期,以及`cls-hooked`简化上下文管理。讨论了`fs.writeFileSync()`在父目录不存在时报错的解决,PowerShell执行Node程序假死,`globalThis`、`global`和`window`的区别,`ArrayBuffer`和`Uint8Array`,以及`readFile()`和`readFileSync()`的选择。
本文记录了老项目启动时遇到的常见问题。问题一为Node.js版本过高导致的OpenSSL错误,解决方案为降级Node.js版本或启用legacy OpenSSL provider。问题二为如何使用git协议安装npm依赖,解决方案为配置SSH密钥后,使用`npm install git+ssh://[email protected]:<username>/<repository>.git`命令安装。
动态(2)
The queueMicrotask() method, which is exposed on the Window or Worker interface, queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.
First, nextTick queue is checked to get tasks for its execution, once it is exhausted, the microTasks queue is checked. After finishing the tasks in the microtask queue the process of checking nextTick and microTasks queues are repeated until the queues have been emptied.
They have different queues. The nextTick's queue is managed by node and the microtask one is managed by v8.
The nextTick queue is checked first after the current function/script execution, and then the microTask one.