简体   繁体   中英

How to start the node.js application using pm2

I have installed pm2 module using the following command:
npm install pm2@latest

Then I tried to start my test application using pm2 as follows:
$ pm2 start test.js

It throws the following error:
'pm2' is not recognized as an internal or external command

Do i need to set environment variable for 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

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.

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,

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

But it won't mostly work on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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