简体   繁体   English

将环境变量传递给pm2无法正常工作

[英]Passing environment variable to pm2 is not working

I have two API in node js using babel and I have a package.json commands to use to make the application working this is the commands: 我在使用babel的js节点中有两个API,我有一个package.json命令可用于使应用程序正常工作,这是以下命令:

"build": "del-cli dist/ && babel src -d dist --copy-files",
"serve": "cross-env NODE_ENV=production node dist/index.js",
"start:noupdate": "cross-env NODE_ENV=development babel-node src/index.js",
"start:serve": "cross-env NODE_ENV=production node dist/index.js",

I have two domains one is https://api.website1.com.br and another is https://website2.com.br/api . 我有两个域,一个是https://api.website1.com.br ,另一个是https://website2.com.br/api

They have the same env file name but with another data for each database, that is .env.production and .env.development 它们具有相同的env文件名,但每个数据库都有另一个数据,即.env.production和.env.development

When I make this "yarn build", my Linux execute this command : 当我进行“纱线构建”时,我的Linux执行以下命令:

"build": "del-cli dist/ && babel src -d dist --copy-files",

And this is working fine when I try to put in production mode on my real webservers, i go to the folder from the project and run this command to make the app online with PM2: 当我尝试在实际的Web服务器上进入生产模式时,这工作正常,我从项目转到文件夹,然后运行以下命令以使应用程序与PM2联机:

pm2 start npm -- run-script start:serve NODE_ENV=production

That will make this command work: 这将使此命令起作用:

"cross-env NODE_ENV=production node dist/index.js"

The app runs just fine, but I have a problem he only runs one and doesn't create a new PM2 APP he just restarts what I start. 该应用程序运行正常,但是我有一个问题,他只能运行一个,而没有创建新的PM2 APP,他只是重新启动了我启动的程序。

Example if I go to the folder in my https://api.website1.com.br and run this command first in this he starts, but I go to the another he doesn't start that but reload my already early app don't create a new one, what I'm doing wrong? 例如,如果我转到我的https://api.website1.com.br中的文件夹并首先运行此命令,则他启动,但是我转到另一个他没有启动但重新加载我已经很早的应用程序,不要创建一个新的,我做错了什么?

I manage to work this using pm2 ecosystem , that I found in this documentation from http://pm2.keymetrics.io/docs/usage/application-declaration/ 我设法使用pm2生态系统来工作,我可以在http://pm2.keymetrics.io/docs/usage/application-declaration/

I configure the default file and put a name my APP: 我配置默认文件并为我的APP命名:

module.exports = {
  apps : [{
    name: "app",
    script: "./app.js",
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }]
}

and use this command pm2 start ecosystem.config.js and now is working, I post here to know if someone has the same problem 并使用此命令pm2启动ecosystem.config.js ,现在可以正常工作了,我在这里发布消息,以了解是否有人遇到相同的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM