搜索
查找主题、作者或分类。
Node.js 24:用内置 test runner 给参数校验做零依赖测试Node.js 自带的 `node:test` 足以覆盖不少小型脚本和 CLI,无需先引入测试框架。下面用一个参数校验函数演示最小可运行结构。
**环境**:Node.js 24.x;Linux、macOS 或 Windows;项目使用 ESM。
先创建 `package.json`:
```json
{
"type": "module",
"scripts": {
"test": "node --test"
}
}
```
创建 `limit.js`:
```js
export function parseLimit(raw) {
const value = Number(raw);
if (!Number.isInteger(value) || value < 1 || value > 100) {
throw new RangeError('limit must be an integer from 1 to 100');
}
return value;
}
```
创建 `limit.test.js`:
```js
@crispmoon45 · 2026/7/28 03:59:03Node.js 服务出现 502:从反向代理到日志定位的排查清单这份清单用于 Linux 上由 Nginx 反向代理、systemd 托管的 Node.js 服务。命令基线为 systemd 245+、Nginx 1.18+、curl 7.68+;Node.js 版本不限,但应记录服务实际使用的二进制版本。示例约定 systemd 单元为 `node-app`、上游为 `127.0.0.1:3000`、健康检查路径为 `/healthz`,执行前请替换为真实值。若 Nginx 或应用位于容器中,`127.0.0.1` 只代表各自容器,连通性检查必须在 Nginx 所在网络命名空间内执行。
以下步骤以只读取证为主。先保留故障现场,不要一看到 502 就立即重启,否则可能丢失进程退出原因和时间关联。
## 0. 记录版本、时间和服务入口
```bash
date -u
node --version
nginx -v
systemctl --version | head -n 1
curl --version | head -n 1
systemctl show node-app -p MainPID -p ExecStart -p User -p@dawn_harbor · 2026/7/27 23:00:12linux@gentlevale36 · 2026/7/27 18:42:00markdowm 测试<div align="center">
<a href="https://dnspup.com/">
<img src="https://dnspup.com/images/dnspup-icon.png?v=ee2cac1a" width="96" height="96" alt="dnspup Logo">
</a>
# dnspup:把网络故障诊断装进浏览器
**在线 Ping · 网站测速 · DNS 查询 · 路由追踪 · IP 纯净度与泄露检测**
[](https://dnspup.com/)
[](https://dnspup.com/)
[![IPv6](https://img.@jiuxian · 2026/7/27 13:16:51