当前位置:网站首页>win配置pm2开机自启node项目
win配置pm2开机自启node项目
2022-07-06 23:55:00 【苦海123】
pm2类似于nodemon,但是功能比nodemon更丰富
1.全局安装pm2,如果你的系统提前没有安装node环境,那么你可以参考博文:https://blog.csdn.net/weixin_46758988/article/details/117109297 ;如果你已经全局安装过pm2,只是没有配置开机自启,那么你也无需重复安装pm2了
npm install pm2 -g 或使用yarn安装(使用yarn前先 npm install yarn -g 全局安装yarn):yarn global add pm2
2.全局安装pm2 Win自启包:pm2-windows-startup:
npm install pm2-windows-startup -g 或 yarn global add pm2-windows-startup
3.安装配置包:pm2-startup
pm2-startup install 或 yarn add pm2-startup
4.使用pm2启动项目,这里可以直接启动你项目中的index.js或app.js,但是还是推荐使用pm2配置文件启动项目,关于pm2配置文件可以参考如下配置文件pm2.config.json(如果想要更详细配置可以查阅官方文档):
{
"apps":{
"name":"myproject-web", // 项目的别名
"script":"index.js", //需要启动程序的入口文件
"watch":"true", // 开启文件变化监听
"ignore_watch":[ // 忽略文件变化监听文件
"node_modules",
"logs"
],
"error_file":"logs/error.log", //配置错误日志输出文件地址
"out_file":"logs/consoles.log", //配置打印日志输出文件地址
"log_date_format":"YYYY-MM-DD HH:mm:ss", //配置日志日期格式
"instances":2 //配置项目所占用的核数,小于等于服务器的总核数量
}
}
5.启动项目:使用pm2启动项目,提前将命令行切换到项目根文件夹下后执行如下命令(如果不切换到项目文件下可以在启动时将项目路径加入启动:pm2 start 路径\index.js):
pm2 start pm2.config.json ,如果没有配置pm2配置文件,那么可以直接通过:pm2 index.js 或 pm2 app.js启动
6.将此项目保存起来,开机后才会自动重启,如:
pm2 save
7.重启服务器,可以正常访问应用,当然我们通常使用命令行下键入命令:pm2 list查看当前启动的项目,这里命令行路径没有要求,如:
pm2 list
提示:本文图片等素材来源于网络,若有侵权,请发邮件至邮箱:[email protected]联系笔者删除。
笔者:苦海
边栏推荐
- High voltage leakage relay bld-20
- batch size设置技巧
- TabLayout修改自定义的Tab标题不生效问题
- Web Authentication API兼容版本信息
- Digital innovation driven guide
- When deleting a file, the prompt "the length of the source file name is greater than the length supported by the system" cannot be deleted. Solution
- JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
- AI face editor makes Lena smile
- 分布式事务介绍
- Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
猜你喜欢
Flink SQL 实现读写redis,并动态生成Hset key
1.AVL树:左右旋-bite
京东商品详情页API接口、京东商品销量API接口、京东商品列表API接口、京东APP详情API接口、京东详情API接口,京东SKU信息接口
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
【js组件】自定义select
ssm框架的简单案例
JVM (19) -- bytecode and class loading (4) -- talk about class loader again
Digital innovation driven guide
AI face editor makes Lena smile
5. 数据访问 - EntityFramework集成
随机推荐
C#可空类型
分布式事务解决方案之2PC
Annotation初体验
AI face editor makes Lena smile
实现网页内容可编辑
C nullable type
The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
SAP ABAP BDC(批量数据通信)-018
Summary of the mean value theorem of higher numbers
Life experience of an update statement
Paper reading [open book video captioning with retrieve copy generate network]
Flink SQL 实现读写redis,并动态生成Hset key
论文阅读【MM21 Pre-training for Video Understanding Challenge:Video Captioning with Pretraining Techniqu】
一条 update 语句的生命经历
Mysql database learning (8) -- MySQL content supplement
Most commonly used high number formula
Cve-2021-3156 vulnerability recurrence notes
JSP setting header information export to excel
English语法_名词 - 所有格
淘宝店铺发布API接口(新),淘宝oAuth2.0店铺商品API接口,淘宝商品发布API接口,淘宝商品上架API接口,一整套发布上架店铺接口对接分享