title: Keeping node.js express running after logoff
body: <p>I've setup a node.js app started with <strong>pm2</strong> and all is working fine</p>
  <p>I've also tried adding watch and save options (see more about the windows service below)</p>
  <pre><code>pm2 start app.js --watch
  pm2 save
  </code></pre>
  <p>but eventually the app is no longer running after I <strong>logoff from Windows</strong> RDP.</p>
  <p>Below the relevant output from <code>pm2 report</code></p>
  <pre><code>==
  PM2        | 2021-04-10T11:26:39: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
  PM2        | 2021-04-10T11:26:39: PM2 log: Time                 : Sat Apr 10 2021 11:26:39 GMT+0200 (Central European Summer Time)
  PM2        | 2021-04-10T11:26:39: PM2 log: PM2 version          : 4.5.6
  PM2        | 2021-04-10T11:26:39: PM2 log: Node.js version      : 14.16.1
  PM2        | 2021-04-10T11:26:39: PM2 log: Current arch         : x64
  PM2        | 2021-04-10T11:26:39: PM2 log: PM2 home             : V:\.pm2
  PM2        | 2021-04-10T11:26:39: PM2 log: PM2 PID file         : V:\.pm2\pm2.pid
  PM2        | 2021-04-10T11:26:39: PM2 log: RPC socket file      : \\.\pipe\rpc.sock
  PM2        | 2021-04-10T11:26:39: PM2 log: BUS socket file      : \\.\pipe\pub.sock
  PM2        | 2021-04-10T11:26:39: PM2 log: Application log path : V:\.pm2\logs
  PM2        | 2021-04-10T11:26:39: PM2 log: Worker Interval      : 30000
  PM2        | 2021-04-10T11:26:39: PM2 log: Process dump file    : V:\.pm2\dump.pm2
  PM2        | 2021-04-10T11:26:39: PM2 log: Concurrent actions   : 2
  PM2        | 2021-04-10T11:26:39: PM2 log: SIGTERM timeout      : 1600
  PM2        | 2021-04-10T11:26:39: PM2 log: ===============================================================================
  
  
  Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues
  </code></pre>
  <p>I wonder whether the pm2 home path could be the root cause, since it is a user share, but I've found how to change it on windows via the <code>PM2_HOME</code> env var and it doesn't do the trick either.</p>
  <p>I've searched the github issues and it seems there are already similar open issues there, for example <a href="https://github.com/Unitech/pm2/issues/4783" rel="nofollow noreferrer">this one</a>:</p>
  <blockquote>
  <p>Same happens if I go directly to server start pm2 and logoff user, all
  processes will be gone. Is there a way to start pm2 on widows globally
  so it doesn't exit when user is logging out ? Or I am doing something
  wrong ?</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>I would also like to understand if there is any option to keep Apps
  running after logging off the user from Windows serve</p>
  </blockquote>
  <p>Anyone has a solution here?</p>
  <p>I've also tried to setup the <code>pm2-windows-service</code> with admin cmd as describe in the <a href="https://github.com/jon-hall/pm2-windows-service" rel="nofollow noreferrer">readme here</a>.</p>
  <p>And I've added a handler for SIGTERM in the express app:</p>
  <pre><code>app.listen(HTTP_PORT, () =&gt; {
      console.log(&quot;Server is listening on port &quot; + HTTP_PORT);
  });
  
  process.on('SIGINT', function() {
      console.log('Do not shut down the app on user log-off');
      //server.close();
    });
  </code></pre>