Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Windows上停止使用永久模块的Node.js应用程序?_Javascript_Node.js_Dom Events - Fatal编程技术网

Javascript 如何在Windows上停止使用永久模块的Node.js应用程序?

Javascript 如何在Windows上停止使用永久模块的Node.js应用程序?,javascript,node.js,dom-events,Javascript,Node.js,Dom Events,关于nodejs应用程序的永久模块,我已经问了很多问题,但没有找到我的答案 Forever模块在Linux机器上运行良好,但现在我将我的应用程序放在Windows 7上,并尝试用Forever运行它。 首先,我将永久模块安装为 npm install forever -g 之后,我运行我的应用程序作为 forever start app.js 它运行良好,说app.js文件是永远运行的,我正在成功访问我的应用程序 当我执行一个命令永远停止app.js时,我得到了一个错误 没有永久文件正在运行

关于nodejs应用程序的永久模块,我已经问了很多问题,但没有找到我的答案

Forever
模块在Linux机器上运行良好,但现在我将我的应用程序放在Windows 7上,并尝试用Forever运行它。 首先,我将永久模块安装为

npm install forever -g
之后,我运行我的应用程序作为

forever start app.js
它运行良好,说app.js文件是永远运行的,我正在成功访问我的应用程序

当我执行一个命令
永远停止app.js
时,我得到了一个错误

没有永久文件正在运行


如果有人在windows上使用了forever,请建议我如何停止windows上的应用程序。

使用
forever list
然后使用id永久停止,例如
永久停止0

下面是一个示例输出

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
这里的
0
类似于输出的第一列中的索引。如果有两个进程正在运行,我们可以使用
0
1
等索引来停止第一个或第二个进程


永远停止0
永远停止1

我也遇到了同样的问题,发现这是因为我使用sudo(Linux上)运行了永远开始,这样我就可以在端口80上运行生产站点。这就成功了:

sudo forever list
这是windows中的一个bug
如果您需要停止应用程序,只需打开任务管理器,找到node.js进程并将其杀死。努力但努力。

这只是为了扩展@laktak的答案。Windows上永久列表的结果如下所示:

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
我不确定最初哪个是ID,但我发现它是上面第二个
数据
字段之后的第一个条目,因此您感兴趣的行是ID粗体和斜体:

数据:[0]an1b
C:\nodejs\node.exe
C:\sbSerialWidget\server.js
8780 1 0152 C:\Users\username.forever\an1b.log已停止

因此,要停止此特定实例,您需要运行:

永久停止0


希望这能帮助像我一样困惑的其他人

你可以按照forever文档进行操作,这里有所有与forever相关的命令

$forever--帮助
用法:永久[操作][选项]脚本[脚本选项]
监视当前进程中指定的脚本或作为守护进程指定的脚本
行动:
作为守护进程启动脚本
通过Id | Uid | Pid | Index |脚本停止守护程序脚本
stopall停止所有永远运行的脚本
重新启动守护程序脚本
重新启动所有正在运行的脚本
列出所有正在运行的脚本
config列出所有用户配置
set设置指定的永久配置
清除清除指定的永久配置
日志列出所有进程的日志文件
日志是日志的尾部
columns add将指定的列添加到“永久列表”中的输出中。支持的列:“uid”、“命令”、“脚本”、“永久”、“pid”、“id”、“日志文件”、“正常运行时间”
columns rm从“永久”列表中的输出中删除了指定的列`
columns set设置“永久”列表中输出的所有列`
cleanlogs[小心]删除所有历史日志文件
选项:
-m MAX只运行指定的脚本MAX次
-l日志文件将永久输出记录到日志文件
-o输出文件记录从子脚本到输出文件的标准输出
-e ERRFILE将stderr从子脚本记录到ERRFILE
-p路径所有永久相关文件(pid文件等)的基本路径
-要执行的c命令(默认为节点)
-a、 --追加日志
-f、 --标准输出的fifo流日志
-n、 --要打印的日志行数
--pid文件pid文件
--uid已弃用。进程uid,用作进程的命名空间(必须用字符串包装)
e、 永远开始——uid“production”app.js
永远停产
--不推荐使用id。进程id,类似于uid,可用作进程的命名空间(必须用字符串包装)
e、 g.永远开始——id“test”app.js
永远停止测试
--sourceDir脚本相对于的源目录
--workingDir脚本将在其中执行的工作目录
--不被视为“旋转”的脚本的分钟最小正常运行时间(毫秒)
--spinSleepTime启动旋转脚本之间的等待时间(毫秒)。
--颜色--没有颜色将禁用输出着色
--普通禁用命令行颜色
-d、 --调试强制永远记录调试输出
-v、 --verbose打开来自Forever的详细消息
-s、 --静默运行子脚本静默stdout和stderr
-w、 --监视文件更改
--watchDirectory要从中监视的顶级目录
--watchIgnore在启用监视时忽略模式(允许多个选项)
-t、 --killTree在“停止”时杀死整个子进程树`
--killSignal支持退出信号自定义(默认为SIGKILL),
用于优雅地重新启动脚本,例如--killSignal=SIGTERM
调用'forever stop/stopall'后生成的任何控制台输出都不会出现在日志中
-h、 “救命啊,你正盯着它呢
[长时间运行过程]
永久进程将继续运行,向控制台输出日志消息。
例如永久-o out.log-e err.log my-script.js
[守护进程]
永久进程将作为使目标进程启动的守护进程运行
在后台。这对于远程简单启动非常有用
 $ 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