在 Debian 上“加速 Node.js”通常可以从系统层面、Node 本身、依赖安装、运行性能几个角度来做。下面按常见场景给你一套可操作方案。
Debian 自带仓库的 Node 通常版本旧、编译优化少。
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
或用 nvm(适合开发):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
nvm use 20
✅ 好处:
npmnpm config set registry https://registry.npmmirror.com
或用 pnpm(更快):
npm i -g pnpm
pnpm install
npm install --prefer-offline --no-audit --no-fund
sudo apt update
sudo apt install linux-image-amd64
CPU 性能模式:
sudo apt install cpufrequtils
sudo cpufreq-set -g performance
const cluster = require('cluster');
if (cluster.isMaster) {
require('os').cpus().forEach(() => cluster.fork());
} else {
require('./app');
}
--max-old-space-sizenode --max-old-space-size=4096 app.js
node --jitless=false --optimize-for-size app.js
curl -fsSL https://bun.sh/install | bash
bun run app.js
curl -fsSL https://deno.land/install.sh | sh
deno run -A app.ts
nginx 反代 + keep-aliveTCP_NODELAY❌ 只升级 Node 不升级依赖
❌ 在 Debian 上用 apt nodejs(旧)
❌ 单进程跑高并发
如果你能说明:
我可以直接给你一套“最优配置命令”。