当前位置:网站首页>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]联系笔者删除。
笔者:苦海
边栏推荐
- Mybaits之多表查询(联合查询、嵌套查询)
- 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
- 拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
- Two person game based on bevy game engine and FPGA
- CVE-2021-3156 漏洞复现笔记
- 淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口
- Common skills and understanding of SQL optimization
- 说一说MVCC多版本并发控制器?
- Tablayout modification of customized tab title does not take effect
- 实现网页内容可编辑
猜你喜欢

Mapbox Chinese map address

Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?

English语法_名词 - 所有格

Lombok plug-in

什么是依赖注入(DI)

Phenomenon analysis when Autowired annotation is used for list

Two person game based on bevy game engine and FPGA

The year of the tiger is coming. Come and make a wish. I heard that the wish will come true

实现网页内容可编辑

阿里云的神龙架构是怎么工作的 | 科普图解
随机推荐
Egr-20uscm ground fault relay
What is dependency injection (DI)
How Alibaba cloud's DPCA architecture works | popular science diagram
C nullable type
Life experience of an update statement
Initial experience of annotation
Différenciation et introduction des services groupés, distribués et microservices
The navigation bar changes colors according to the route
Leakage relay jd1-100
Jhok-zbg2 leakage relay
张平安:加快云上数字创新,共建产业智慧生态
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
【Shell】清理nohup.out文件
《2》 Label
Summary of the mean value theorem of higher numbers
什么是消息队列?
1. AVL tree: left-right rotation -bite
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
Preliminary practice of niuke.com (9)
Leetcode: maximum number of "balloons"