【发布时间】:2022-10-25 09:10:32
【问题描述】:
我在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();
})();
它适用于命令节点 index.js。
但是当我想用pm2 运行它时
使用 cmd pm2 start ecosystem.config.js --env=productionecosystem.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"],
},
],
};
我不知道为什么会这样,node index.js 可以工作,但PM2 不能工作?
【问题讨论】:
-
您能否提供脚本的第 16 行
test.js -
此外,您的生态系统文件中有错字。请将
evn替换为env