title: PM2 Script Not Found for bin/www
body: <p>Recently i decided to run my app with pm2 as a service. For me <code>pm2 start app.mjs</code> runs the app as a service but it seems pm2 doesn't run my express application correctly. I used express npm to build an app like this:</p>
  <pre><code>//Imports
  import express from &quot;express&quot;;
  
  //Setups
  const app = express();
  const port = process.env.PORT;
  
  app.get(&quot;/&quot;, async (req, res) =&gt; {
    res.send(&quot;Hello world!&quot;);
  });
  
  //Running server
  app.listen(port, () =&gt; {
    console.log(`Server is running on port ${port}`);
  });
  </code></pre>
  <p>Also tried <code>pm2 start ./bin/www</code> that gives me an <code>Script not found</code> error and it seems to be okay with <code>express-generator</code> not the express npm alongside an app. App works correctly in dev mode (<code>node app.mjs</code>).</p>
  <p><strong>UPDATE</strong></p>
  <p>I solved the problem with help of <a href="https://stackoverflow.com/users/12565601/konstantinos-lamogiannis">Konstantinos Lamogiannis</a>. After setup the config file as well as the answer, i changed my <code>app.mjs</code> to <code>app.js</code> form and changed the <code>import</code> style to <code>const variable = require(&quot;&quot;);</code> and it fixed my problem. I don't know why that happened but it seems the <code>pm2</code> npm may confilct with new nodejs feature which supports the <code>import</code> ES6 syntax.</p>
  <p>pm2 log was giving to me this error: unhandledRejection you may have forgotten to catch a Promise rejection !</p>