Search code examples
node.jsnpmpm2

Kill process started with NPM (pm2)


I installed pm2 with NPM without the global flag. Then I started the app with "npm start" that declared on package.json as

"start": "pm2 start index.js"

How can I stop it?


Solution

  • You can access locally-installed pm2 with npx:

    $ npx pm2 list
    $ npx pm2 stop 0 # first app will have ID=0
    

    But in general, I would manage it by attaching a name to the app. Let's edit your package.json:

    "start": "pm2 start index.js --name my-app"
    "stop": "pm2 stop my-app",
    "logs": "pm2 logs my-app"
    

    And then:

    $ npm run start
    $ npm run logs
    $ npm run stop