【问题标题】:How can I kill an express process when is running in a port在端口中运行时如何终止快速进程
【发布时间】:2019-11-02 04:59:24
【问题描述】:

我在我的 Electron 项目中使用 express 模块,当我尝试关闭此服务时

        expreso.get('/test', function(req, res, next){    
            res.json({"key": "value"});   
            newWin.reload();
        })  

仍在同一个端口工作...

express.close() 不起作用,模块 https://github.com/moebius-mlm/http-graceful-shutdownhttps://www.npmjs.com/package/kill-port 也不起作用

        service = new BrowserWindow({
            webPreferences: {
                nodeIntegration: true,
                alwaysOnTop: false,
            },
            show: false,
            frame: false,
            skipTaskbar: true,
        })
        service.once('ready-to-show', () => {
            service.show()
          })
        service.setMenu(null)
        service.setSize(600, 400)
        service.setPosition(0, 0)
        service.loadURL("http://192.168.6.58:9001/genius/logout")
        service.close()

        newWin.close()
        newWin = new BrowserWindow({
            webPreferences: {
                nodeIntegration: true,
                alwaysOnTop: true,
                skipTaskbar: true,
            },
            show: false,
            frame: false,
        })
        newWin.show()
        newWin.setMenu(null)
        newWin.setSize(600, 400)
        newWin.setPosition(0, 0)
        newWin.loadURL("http://192.168.6.58:5000/logout/192.168.4.216")
        setTimeout(function(){ newWin.close(); }, 5000)
        server.close();

最后的server.close() 没有按我的预期工作。

https://i.imgur.com/DEgwOgn.png

【问题讨论】:

    标签: node.js express service electron


    【解决方案1】:

    您是 Windows 用户。输入命令查找正在运行的进程如下图:

    ps
    

    然后你会看到这样的东西:

    PID   PPID  PGID  WINPID TTY   UID    STIME    COMMAND
    8468  29784 8468  29576  cons1 197609 21:43:58 /usr/bin/ps
    29784 1     29784 29784  cons1 197609 16:12:58 /usr/bin/bash 
    11220 26724 26724 35960  cons0 197609 16:13:41 /c/Program Files/nodejs/node 
    26724 9976  26724 31940  cons0 197609 16:13:41 /usr/bin/sh
    9976  1     9976  9976   cons0 197609 09:14:22 /usr/bin/bash
    

    你看到节点的`PID'是11220了吗?再次,在 shell 中输入命令:

    kill -9 11220
    

    然后键入命令ps,它看起来像这样:

    PID   PPID  PGID  WINPID TTY   UID    STIME    COMMAND
    8468  29784 8468  29576  cons1 197609 21:43:58 /usr/bin/ps
    29784 1     29784 29784  cons1 197609 16:12:58 /usr/bin/bash 
    26724 9976  26724 31940  cons0 197609 16:13:41 /usr/bin/sh
    9976  1     9976  9976   cons0 197609 09:14:22 /usr/bin/bash
    

    如果您按照上述命令操作,您现在应该能够在端口 3000 上再次运行服务器。

    【讨论】:

      猜你喜欢
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      相关资源
      最近更新 更多