How to stop Node.js application using forever module on Windows?

Javascriptnode.jsDom Events

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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 - Javascript

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 - Javascript

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

Solution 4 - Javascript

It's a bug in windows https://github.com/nodejitsu/forever/issues/337 If you need to stop your app just open task manager and find node.js process and kill it. Hard but work.

Solution 5 - Javascript

forever stop 0

where the 0 is the index of your app running, if you just have one so is 0.

Solution 6 - Javascript

You can follow the forever documents there are all commands related to forever.

Forever

 $ forever --help
      usage: forever [action] [options] SCRIPT [script-options]
    
      Monitors the script specified in the current process or as a daemon
    
      actions:
        start               Start SCRIPT as a daemon
        stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
        stopall             Stop all running forever scripts
        restart             Restart the daemon SCRIPT
        restartall          Restart all running forever scripts
        list                List all running forever scripts
        config              Lists all forever user configuration
        set <key> <val>     Sets the specified forever config <key>
        clear <key>         Clears the specified forever config <key>
        logs                Lists log files for all forever processes
        logs <script|index> Tails the logs for <script|index>
        columns add <col>   Adds the specified column to the output in `forever list`. Supported columns: 'uid', 'command', 'script', 'forever', 'pid', 'id', 'logfile', 'uptime'
        columns rm <col>    Removed the specified column from the output in `forever list`
        columns set <cols>  Set all columns for the output in `forever list`
        cleanlogs           [CAREFUL] Deletes all historical forever log files

  options:
    -m  MAX          Only run the specified script MAX times
    -l  LOGFILE      Logs the forever output to LOGFILE
    -o  OUTFILE      Logs stdout from child script to OUTFILE
    -e  ERRFILE      Logs stderr from child script to ERRFILE
    -p  PATH         Base path for all forever related files (pid files, etc.)
    -c  COMMAND      COMMAND to execute (defaults to node)
    -a, --append     Append logs
    -f, --fifo       Stream logs to stdout
    -n, --number     Number of log lines to print
    --pidFile        The pid file
    --uid            DEPRECATED. Process uid, useful as a namespace for processes (must wrap in a string)
                     e.g. forever start --uid "production" app.js
                         forever stop production
    --id             DEPRECATED. Process id, similar to uid, useful as a namespace for processes (must wrap in a string)
                     e.g. forever start --id "test" app.js
                         forever stop test
    --sourceDir      The source directory for which SCRIPT is relative to
    --workingDir     The working directory in which SCRIPT will execute
    --minUptime      Minimum uptime (millis) for a script to not be considered "spinning"
    --spinSleepTime  Time to wait (millis) between launches of a spinning script.
    --colors         --no-colors will disable output coloring
    --plain          Disable command line colors
    -d, --debug      Forces forever to log debug output
    -v, --verbose    Turns on the verbose messages from Forever
    -s, --silent     Run the child script silencing stdout and stderr
    -w, --watch      Watch for file changes
    --watchDirectory Top-level directory to watch from
    --watchIgnore    To ignore pattern when watch is enabled (multiple option is allowed)
    -t, --killTree   Kills the entire child process tree on `stop`
    --killSignal     Support exit signal customization (default is SIGKILL),
                     used for restarting script gracefully e.g. --killSignal=SIGTERM
                     Any console output generated after calling `forever stop/stopall` will not appear in the logs
    -h, --help       You're staring at it

  [Long Running Process]
    The forever process will continue to run outputting log messages to the console.
    ex. forever -o out.log -e err.log my-script.js

  [Daemon]
    The forever process will run as a daemon which will make the target process start
    in the background. This is extremely useful for remote starting simple node.js scripts
    without using nohup. It is recommended to run start with -o -l, & -e.
    ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
        forever stop my-daemon.js

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSatyendra FauzdarView Question on Stackoverflow
Solution 1 - JavascriptlaktakView Answer on Stackoverflow
Solution 2 - JavascriptMorgan HerlockerView Answer on Stackoverflow
Solution 3 - JavascriptdelliottgView Answer on Stackoverflow
Solution 4 - JavascriptIlya ZaytsevView Answer on Stackoverflow
Solution 5 - JavascriptMoises MarquesView Answer on Stackoverflow
Solution 6 - JavascriptAnkit Kumar RajpootView Answer on Stackoverflow