How to stop app that node.js express 'npm start'

后端 未结 16 2012
名媛妹妹
名媛妹妹 2020-12-07 11:00

You build node.js app with express v4.x then start your app by npm start. My question is how to stop the app? Is there npm stop?

相关标签:
16条回答
  • 2020-12-07 11:17

    You can use pm2

    https://pm2.keymetrics.io/docs/usage/quick-start/

    after installation just type in terminal

    pm2 start app.js and then

    pm2 stop 0 to stop your server

    0 讨论(0)
  • 2020-12-07 11:22

    Check with netstat -nptl all processes

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      1736/mongod     
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1594/sshd       
    tcp6       0      0 :::3977                 :::*                    LISTEN      6231/nodejs     
    tcp6       0      0 :::22                   :::*                    LISTEN      1594/sshd       
    tcp6       0      0 :::3200                 :::*                    LISTEN      5535/nodejs 
    

    And it simply kills the process by the PID reference.... In my case I want to stop the 6231/nodejs so I execute the following command:

    kill -9 6231
    
    0 讨论(0)
  • 2020-12-07 11:23

    If is very simple, just kill the process..

    localmacpro$ ps
      PID TTY           TIME CMD
     5014 ttys000    0:00.05 -bash
     6906 ttys000    0:00.29 npm   
     6907 ttys000    0:06.39 node /Users/roger_macpro/my-project/node_modules/.bin/webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
     6706 ttys001    0:00.05 -bash
     7157 ttys002    0:00.29 -bash
    
    localmacpro$ kill -9 6907 6906
    
    0 讨论(0)
  • 2020-12-07 11:25

    You have to press combination ctrl + z My os is Ubuntu

    0 讨论(0)
  • 2020-12-07 11:26

    All (3) solotion is :

    1- ctlr + C

    2- in json file wreite a script that stop

    "scripts": { "stop": "killall -SIGINT this-name-can-be-as-long-as-it-needs-to-be" },

    *than in command write // npm stop //

    3- Restart the pc

    0 讨论(0)
  • 2020-12-07 11:27

    Yes, npm provides for a stop script too:

    npm help npm-scripts

    prestop, stop, poststop: Run by the npm stop command.

    Set one of the above in your package.json, and then use npm stop

    npm help npm-stop

    You can make this really simple if you set in app.js,

    process.title = myApp;

    And, then in scripts.json,

    "scripts": {
        "start": "app.js"
        , "stop": "pkill --signal SIGINT myApp"
    }
    

    That said, if this was me, I'd be using pm2 or something the automatically handled this on the basis of a git push.

    0 讨论(0)
提交回复
热议问题