How to start the node.js application using pm2
Asked Answered
M

3

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?

Mattiematting answered 4/8, 2016 at 8:6 Comment(2)
Why not try that option first? Yes, I think you do need to.Pinter
install with -g option npm install pm2 -gAvictor
B
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.

Boastful answered 4/8, 2016 at 8:10 Comment(1)
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.Savdeep
L
8

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.

Leoraleos answered 6/5, 2021 at 7:17 Comment(2)
Oh my goodness thank you so much. I was trying to follow the install instructions for pm2-windows-startup (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...Longcloth
It helped me by putting it on a Windows Server 2019Reginaldreginauld
S
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.

Senary answered 14/6, 2021 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.