简体   繁体   English

使用 pm2 将节点作为服务运行

[英]Run node as a service with pm2

I am trying to run a node api as a service but when I run the following command我正在尝试将节点 api 作为服务运行,但是当我运行以下命令时

C:\Windows\System32>pm2-service-install -n 0PM2 

it asks the following question它问了以下问题

Perform environment setup (recommended)?

I put yes but it stays there and does nothing我说是,但它一直呆在那里,什么也不做

What could be the problem?可能是什么问题呢?

You can simply install the pm2 package.您可以简单地安装pm2包。

npm install pm2 -g

Run the module that has your server运行有你的服务器的模块

 pm2 start app.js

If the above things are working fine, it shows your installation and configuration are correct.如果以上一切正常,则表明您的安装和配置是正确的。 Now, use pm2 commands:现在,使用pm2命令:

pm2 startup

follow the command from the o/p of above command按照上述命令的 o/p 中的命令

pm2 save

It seems you are using windows, you should use these steps:看来您正在使用 Windows,您应该使用以下步骤:

  1. download the pm2-installer from here .这里下载pm2-installer
  2. Copy the entire pm2-installer directory onto the target machine, then run:将整个 pm2-installer 目录复制到目标机器上,然后运行:
npm run setup
  1. On Windows, the setup script assumes you have already configured npm to use prefix and cache directories in a location accessible to the Local Service user.在 Windows 上,安装脚本假定您已将 npm 配置为在本地服务用户可访问的位置使用前缀和缓存目录。 If not, it will issue a warning and ask if you're sure you'd like to proceed.如果没有,它会发出警告并询问您是否确定要继续。 To set up npm automatically, run configure first:要自动设置 npm,请先运行 configure:
npm run configure
npm run setup

Check here for more details.在这里查看更多详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM