title: Node.js getting SIGINT from pm2
body: <p>I'm trying to use pm2 to run my node app as a service.</p>
  
  <p>Right now, starting and stopping the app works. However, I want to do a graceful shutdown.</p>
  
  <p>My app already listens for SIGINT, shutdowns the server and then exits the process. However, trying to put pm2 to send the SIGINT, just causes the app to restart, like if pm2 was killing and starting it again.</p>
  
  <p>This is how I create the process:</p>
  
  <blockquote>
    <p>pm2 start server.js --name ProcessName --silent --kill-timeout 3000</p>
  </blockquote>
  
  <p>Here's my app's code for listening the SIGINT:</p>
  
  <pre><code>process.on("SIGINT", function () {
      //graceful shutdown
      server.end().then(() =&gt; {
          process.exit();
      }).catch((err) =&gt; {
          console.error(err);
      });
  
  });
  </code></pre>
  
  <p>Then to shutdown the app using pm2, I'm running:</p>
  
  <blockquote>
    <p>pm2 sendSignal SIGINT ProcessName</p>
  </blockquote>
  
  <p>Which, again, restarts the app.</p>
  
  <p>Reading over pm2 docs, I found that pm2 will also send a <code>shutdown</code> event to the app, so I added:</p>
  
  <pre><code>process.on('message', function(msg) {
      if (msg == 'shutdown') {
          server.end().then(() =&gt; {
              process.exit();
          }).catch((err) =&gt; {
              console.error(err);
          });
      }
  });
  </code></pre>
  
  <p>Which isn't working either.</p>
  
  <p>Any idea how to solve this?</p>
  
  <p>Thanks!</p>