简体   繁体   中英

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:

"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 .

They have the same env file name but with another data for each database, that is .env.production and .env.development

When I make this "yarn build", my Linux execute this command :

"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:

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.

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?

I manage to work this using pm2 ecosystem , that I found in this documentation from http://pm2.keymetrics.io/docs/usage/application-declaration/

I configure the default file and put a name my 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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