title: ExpressJS Server Goes Offline Every Night - 502 Bad Gateway
body: <p>I have a website with Nginx installed as a reserve proxy for an ExpressJS server (proxies to port 3001). This uses Node and ReactJS for my frontend application.</p>
  
  <p>This is simply a testing website currently, and isn't known or used by any users. I have this installed on a Digital Ocean Droplet with Ubuntu.</p>
  
  <p>Every morning when I wake up, I load my website and see <code>502 Bad Gateway</code>. The problem is, I don't know how to find out how this happened. I have PM2 installed which should automatically restart my ExpressJS server but it hasn't done so, and when I run <code>pm2 list</code>, my application is still showing <code>online</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/FmhSQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FmhSQ.png" alt="enter image description here"></a></p>
  
  <p>When I run <code>pm2 logs</code>, I get the following error (I am running this as an Administrator):</p>
  
  <p><a href="https://i.stack.imgur.com/xtZaC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xtZaC.png" alt="enter image description here"></a></p>
  
  <p>So I'll run <code>pm2 restart all</code> to restart the app, but then I don't see any crash information. However on this occasion when taking this screenshot, there were a couple of unusual requests. <code>/robots.txt</code>, <code>/sitemap.xml</code> and <code>/.well-known/security.txt</code>, but nothing indicating a crash:</p>
  
  <p><a href="https://i.stack.imgur.com/6SLCE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6SLCE.png" alt="enter image description here"></a></p>
  
  <p>When I look at my Nginx <code>error.log</code> file, all I can see is the following:</p>
  
  <p><a href="https://i.stack.imgur.com/tkfee.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tkfee.png" alt="enter image description here"></a></p>
  
  <p>There is, however, something obscure within my <code>access.log</code> (<code>[09/Oct/2018:06:33:19 +0000]</code>) but I have no idea what this means:</p>
  
  <p><a href="https://i.stack.imgur.com/1dClC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1dClC.png" alt="enter image description here"></a></p>
  
  <p>If I run <code>curl localhost:3001</code> whilst the server is offline, I will receive a connection error message. This works fine after I run <code>pm2 restart all</code>.</p>
  
  <p>I'm completely stuck with this and even the smallest bit of help would be appreciated greatly, even if it's just to tell me I'm barking up the wrong tree completely and need to look elsewhere - thank you.</p>