How to stop Node.js application using forever module on Windows?
I have gone through so many questions regarding forever module for nodejs APP, but did not find my answer.
Forever
module is working fine on a Linux box but now I am putting my APP on Windows 7 and trying to run it with forever.
First i installed forever module as
npm install forever -g
after that I ran my app as
forever start app.js
it's running fine by saying file app.js is running with forever and I am accessing my app successfully.
When I execute a command forever stop app.js
I get the error
no forever file is running
Please suggest me if anyone has used forever on windows that how can I stop my application on Windows.
Solution 1:
use forever list
then forever stop with the id, e.g. forever stop 0
Here is a sample output
user@some-server]$ forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] 9Xzw ng serve --host 0.0.0.0 --port 4009 13164 29579 /home/ec2-user/.forever/9Xzw.log 7:1:20:50.412
data: [1] wOj1 npm run-script app-start-dev 29500 24978 /home/ec2-user/.forever/wOj1.log 0:0:5:3.433
Here 0
is like an index which is in the first column of the output. If there are two processes running, we can use indexes like 0
or 1
to stop the first or the second process.
forever stop 0
OR forever stop 1
Solution 2:
I had this same issue and found that it was because I was running forever start with sudo (on Linux) so that I could run a production site on port 80. This did the trick:
sudo forever list
Solution 3:
This is just to expand on @laktak's answer. The result of forever list
on Windows will look something like this:
info: Forever processes running
data: uid command script forever p
id id logfile uptime
data: [0] an1b "C:\nodejs\node.exe" C:\sbSerialWidget\server.js 8780 1
0152 C:\Users\username\.forever\an1b.log STOPPED
I wasn't sure which one was the ID initially, but I figured out that it was the first entry after the second data
field above, so the line you're interested in is with the ID bolded & italicized:
data: [0] an1b C:\nodejs\node.exe
C:\sbSerialWidget\server.js
8780 1
0152 C:\Users\username.forever\an1b.log STOPPED
So to stop this particular instance, you'd run:
forever stop 0
Hope this helps someone else who was confused like I was