0

I've this simple code in index.js

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.pdf({ path: './prints/test.pdf', format: 'A4' });

  await browser.close();
})();

It works with command node index.js.
BUT when I want to run it with pm2 with cmd pm2 start ecosystem.config.js --env=production
ecosystem.config.js

module.exports = {
  apps: [
    {
      name: "print_ca",
      script: "index.js",
      evn: {
        NODE_ENV: "development",
      },
      env_production: {
        NODE_ENV: "production",
      },
      instances: 1,
      exec_mode: "fork",
      ignore_watch: ["node_modules", "prints", "storage"],
    },
  ],
};

But shows the error: enter image description here

I don't know why it happens, with node index.js it works but with PM2 won't work?

XMehdi01
  • 5,538
  • 2
  • 10
  • 34
  • Can you provide line #16 of your script `test.js` – Alaindeseine Oct 12 '22 at 13:43
  • Also, you have a typo in you ecosystem file. Please repalce `evn` by `env` – Alaindeseine Oct 12 '22 at 13:44
  • Please no images of errors: [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) – ggorlen Oct 12 '22 at 15:09

1 Answers1

0

The user's right to start the pm2 process is not enough to access the feature file. try to restart the pm2 in service with the admin account

will
  • 1