在 Debian 上遇到 Node.js 运行/安装/构建慢 的问题,通常可以从系统、网络、Node 版本、依赖管理、构建配置几个方面优化。下面按常见场景给你一套实用方案。
npm config set registry https://registry.npmmirror.com
验证:
npm config get registry
yarn config set registry https://registry.npmmirror.com
编辑:
sudo sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
sudo apt update
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
sudo sysctl -w net.core.somaxconn=1024
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
nvm use 20
NODE_ENV=production node app.js
debugconsole.lognpm install -g pm2
pm2 start app.js -i max
node --max-old-space-size=2048 app.js
npm install --prefer-offline --no-audit --no-fund
npm i -g pnpm
pnpm install
npm cache clean --force
sudo apt install -y build-essential python3
npm install --build-from-source=false
node:20-slimpackage.json 再 npm installNODE_ENV=production如果你能说清楚:
我可以给你针对性更强的优化方案。