6

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?

Prem
  • 5,685
  • 15
  • 52
  • 95

3 Answers3

14

You need to install PM2 globally via npm install --global pm2@latest and if you want to use the local version, try ./node_modules/.bin/pm2 start test.js.

Umayr
  • 933
  • 1
  • 10
  • 19
  • I had similar issue on the Azure App Service, this solution works. Also I tried to restart the app service then pm2 command started working. – Sivalingaamorthy Aug 19 '20 at 10:42
5

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.

Naresh Nagpal
  • 299
  • 4
  • 6
  • Oh my goodness thank you so much. I was trying to follow the install instructions for `pm2-windows-startup` (https://www.npmjs.com/package/pm2-windows-startup) and when I tried `pm2-startup install`, it kept telling me `pm2-startup is not recognized as an internal or external command...` – velkoon Jun 08 '21 at 22:57
3

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.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81