欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > IT工具 | node.js 进程管理工具 PM2 大升级!支持 Bun.js

IT工具 | node.js 进程管理工具 PM2 大升级!支持 Bun.js

2025/3/19 17:56:51 来源:https://blog.csdn.net/ssrc0604hx/article/details/146332418  浏览:    关键词:IT工具 | node.js 进程管理工具 PM2 大升级!支持 Bun.js

P(rocess)M(anager)2 是一个 node.js 下的进程管理器,内置负载均衡,支持应用自动重启,常用于生产环境运行 node.js 应用,非常好用👍

🌼概述

2025-03-15日,PM2发布最新版本v6.0.5,这是一个大版本升级(上一版本v5.4.2发布于24年7月),本次更新带来了 Bun.js 的支持🎉。

  • 支持 Bun.js 运行时
  • 默认禁用 git 解析
  • PM2 serve 响应增加 WEBP 内容类型

⬆️版本升级

此处以 windows 平台为例进行说明

# 查看当前版本
pm2 -v
# 5.3.0# 直接通过以下命令覆盖安装
npm i -g pm2
# added 13 packages, removed 63 packages, and changed 121 packages in 1m
# 13 packages are looking for funding
#   run `npm fund` for details

升级后,我们执行 pm2 ls(显示pm2管理的进程)命令,会得到以下提示:

>>>> In-memory PM2 is out-of-date, do:
>>>> $ pm2 update
In memory PM2 version: 5.3.0
Local PM2 version: 6.0.5

我们执行pm2 update即可。

$ pm2 update-------------██████╗ ███╗   ███╗██████╗     ██╗    ██╗ ██████╗██╔══██╗████╗ ████║╚════██╗    ██║   ██╔╝██╔═══██╗██████╔╝██╔████╔██║ █████╔╝    ██║  ██╔╝ ██║   ██║██╔═══╝ ██║╚██╔╝██║██╔═══╝     ██║ ██╔╝  ██║   ██║██║     ██║ ╚═╝ ██║███████╗    ██║██╔╝   ╚██████╔╝╚═╝     ╚═╝     ╚═╝╚══════╝    ╚═╝╚═╝     ╚═════╝https://pm2.io/Harden your Node.js Production Environment- Real-time Monitoring Web Interface- Pro Active Alerting System- Production Profiling for Memory and CPU- PM2 Runtime High Availability FallbackStart using it by typing:$ pm2 plus-------------[PM2][WARN] No process found
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped
[PM2] Spawning PM2 daemon with pm2_home=C:\Users\admin\.pm2
[PM2] Restoring processes located in C:\Users\admin\.pm2\dump.pm2
>>>>>>>>>> PM2 updated

🛠️小试牛刀

安装 Bun.js

如果您已经安装,请跳过😄

# windows 下安装 bun.js
powershell -c "irm bun.sh/install.ps1|iex"# 升级
bun upgrade# 卸载
powershell -c ~\.bun\uninstall.ps1

示例代码

我们让 deepseek 写一段简单的 WEB 服务

import http from 'http';
import url from 'url';// 记录程序启动时间
const startTime = Date.now();// 创建 HTTP 服务器
const server = http.createServer((req, res) => {const parsedUrl = url.parse(req.url, true);// 处理 /status 路由if (parsedUrl.pathname === '/status') {// 计算程序已经运行的时间(秒)const uptime = Math.floor((Date.now() - startTime) / 1000);// 返回 JSON 响应res.writeHead(200, { 'Content-Type': 'application/json' });res.end(JSON.stringify({ uptime }));} else {// 处理其他路由res.writeHead(404, { 'Content-Type': 'text/plain' });res.end('Not Found');}
});// 监听端口
const PORT = 3000;
server.listen(PORT, () => {console.log(`Server is running on http://localhost:${PORT}`);
});

运行进程

# 使用 node.js 运行
pm2 start web-node.mjs --interpreter node
# 使用 bun.js 运行
pm2 start web-bun.mjs --interpreter bun


运行4h后的状态:

运行7h后的状态:

Bun.js 跑的应用占用的内存越来越低?😂

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词