title: How can I fix issues launching an app in PM2 on Windows?
body: <p>I am trying to run <a href="https://v2.docusaurus.io/docs/installation" rel="nofollow noreferrer">Docusaurus</a> on Windows Server 2016 with Node.js version 12.14.0 via PM2 on IIS10. I am using PM2 so I can have the apps restart after a server reboot. I have to admit now that today is the first time I have ever attempted anything with Node.js, so please bear with me.</p>
  
  <p>This is <a href="https://v2.docusaurus.io/docs/installation#running-the-development-server" rel="nofollow noreferrer">usually run</a> by calling <code>npm run start</code> within the Docusaurus directory. When testing out Node.js and whether a 'Hello World' app would start on reboot of the server, I was using the <code>ecosystem.config.js</code> as suggested in the PM2 documentation. This called a javascript file like so.</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports = {
      apps: [
        {
          name: "HelloWorld",
          script: "apps\\hello_world.js",
          instances: 1
        }
      ]
    }
  </code></pre>
  
  <p>This worked fine, but I could not find any documentation on how to run <code>npm start</code> from this file though (although I did try calling a separate batch file, which also didn't work). Then I saw <a href="https://stackoverflow.com/a/42619477/9164015">here</a> that I could call a JSON file that documented further options.</p>
  
  <p>JSON configuration file:</p>
  
  <pre><code>{
      "apps": [
          {
              "name": "docs",
              "cwd": "apps\\docs",
              "script": "npm",
              "args": "start"
          },
          {
              "name": "HelloWorld",
              "script": "apps\\hello_world.js"
          }
      ]
  }
  </code></pre>
  
  <p>The 'HelloWorld' script starts, but not the docs app.</p>
  
  <p>pm2 report offers the following output:</p>
  
  <pre><code>PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
  PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
  PM2        | 2020-01-07T17:54:22: PM2 log: Script C:\PROGRAM FILES\NODEJS\NPM.CMD had too many unstable restarts (16). Stopped. "errored"
  </code></pre>
  
  <p>Which brought me to <a href="https://github.com/Unitech/pm2/issues/4429" rel="nofollow noreferrer">this</a> issue on GitHub. There doesn't seem to be a lot of activity on the issues there though, and there were historic occurrences of it too.</p>
  
  <p>I think there may be something I am doing wrong with PM2 or there is a problem with it, because I cannot launch docs via the command line with PM2 either.</p>
  
  <pre class="lang-sh prettyprint-override"><code>C:\Node JS\apps\docs&gt;pm2 start npm --name "docs" -- start
  </code></pre>
  
  <p>Has anyone got any ideas on how I can get this to work or has tried to do anything similar? I would settle for an answer on: </p>
  
  <ul>
  <li>An alternative way to run Docusaurus on Windows Server.</li>
  <li>An alternative to using PM2.</li>
  <li>Any other ideas.</li>
  </ul>
  
  <p>Apologies if I have rambled.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Output of <code>pm2 start ecosystem.json --only docs</code></p>
  
  <pre class="lang-sh prettyprint-override"><code>C:\Node JS&gt;pm2 start ecosystem.json --only docs
  [PM2][WARN] Applications docs not running, starting...
  [PM2][ERROR] Process failed to launch EPERM: operation not permitted, open 'C:\etc\.pm2\logs\docs-out.log'
  </code></pre>
  
  <p>The log it references is empty. The <code>docs-error.log</code> repeats the same error repeatedly, but has not been updated since last night. It was probably created from me trying out different syntaxes in the JSON file, but posting it anyway.</p>
  
  <pre class="lang-sh prettyprint-override"><code>SyntaxError: Unexpected token ':'
      at Module._compile (internal/modules/cjs/loader.js:895:18)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
      at Module.load (internal/modules/cjs/loader.js:815:32)
      at Function.Module._load (internal/modules/cjs/loader.js:727:14)
      at Object.&lt;anonymous&gt; (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
      at Module._compile (internal/modules/cjs/loader.js:959:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
      at Module.load (internal/modules/cjs/loader.js:815:32)
      at Function.Module._load (internal/modules/cjs/loader.js:727:14)
      at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
  C:\PROGRAM FILES\NODEJS\NPM.CMD:1
  :: Created by npm, please don't edit manually.
  </code></pre>