简体   繁体   English

如何使用 pm2 启动 node.js 应用程序

[英]How to start the node.js application using pm2

I have installed pm2 module using the following command:我已经使用以下命令安装了 pm2 模块:
npm install pm2@latest npm 安装 pm2@latest

Then I tried to start my test application using pm2 as follows:然后我尝试使用 pm2 启动我的测试应用程序,如下所示:
$ pm2 start test.js $ pm2 开始 test.js

It throws the following error:它引发以下错误:
'pm2' is not recognized as an internal or external command “pm2”未被识别为内部或外部命令

Do i need to set environment variable for pm2?我需要为 pm2 设置环境变量吗?

您需要通过npm install --global pm2@latest全局安装 PM2,如果您想使用本地版本,请尝试./node_modules/.bin/pm2 start test.js

After installing PM2, we may need to add following value to path variable under Environment Variables安装 PM2 后,我们可能需要在 Environment Variables 下的 path 变量中添加以下值

C:\\Users\\USERNAME\\AppData\\Roaming\\npm

After adding, reopen the command prompt.添加后,重新打开命令提示符。

You might installed the pm2 locally instead of global scope, this is due to missing -g parameter in your installation command.您可能在本地安装 pm2 而不是全局范围,这是由于安装命令中缺少 -g 参数。

npm install -g pm2

or

yan add -g pm2

If you tried npm install pm2 then the module will install locally to the app that you are currently developing from there you can invoke the pm2 using,如果您尝试使用npm install pm2那么该模块将在本地安装到您当前正在开发的应用程序中,您可以使用以下方法调用 pm2,

./node_modules/pm2/bin/pm2 start index.js

But it won't mostly work on windows.但它不会主要在 Windows 上工作。 Try to use the global install option.尝试使用全局安装选项。

You are getting the same error after global install option then add the npm path in your environment variables.在全局安装选项之后您遇到相同的错误,然后在您的环境变量中添加 npm 路径。

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

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