我的ecosystem.config.js
中有一个这样的环境变量
ORGANIZATION: {
"b0fd9120-deb7-55t6-b269-c1622a43e9af": {
ORG_NAME: "org 1",
RAZORPAY: {
KEY: 'randomkey1',
SECRET:'randomsecret1'
},
},
"ab5003c0-deb7-11e9-334s-c1622ayyy9af": {
ORG_NAME: "org 2",
RAZORPAY: {
KEY: 'randomkey2',
SECRET:'randomsecret2'
},
}
},
完整的ecosystem.config.js
看起来像这样
module.exports = {
apps: [
// First application
{
name: 'Myapp',
script: 'startserver.sh',
max_memory_restart: '1024M',
env_production: {
DATABASE: 'a',
USERNAME: 'a',
PASSWORD: 'a',
HOST: 'd',
PORT: '2929',
DB_PORT: '5432',
ORGANIZATION: {
"b0fd9120-deb7-55t6-b269-c1622a43e9af": {
ORG_NAME: "org1",
RAZORPAY: {
KEY: 'dd',
SECRET: 'dd'
},
},
"ab5003c0-deb7-11e9-334s-c1622ayyy9af": {
ORG_NAME: "org2",
RAZORPAY: {
KEY: 'dd',
SECRET: 'dd'
},
}
},
},
env_staging: {
DATABASE: 'a',
USERNAME: 'a',
PASSWORD: 'a',
HOST: 'd',
PORT: '2929',
DB_PORT: '5432',
ORGANIZATION: {
"b0fd9120-deb7-55t6-b269-c1622a43e9af": {
ORG_NAME: "org1",
RAZORPAY: {
KEY: 'dd',
SECRET: 'dd'
},
},
"ab5003c0-deb7-11e9-334s-c1622ayyy9af": {
ORG_NAME: "org2",
RAZORPAY: {
KEY: 'dd',
SECRET: 'dd'
},
}
},
}
}
],
};
startserver.sh
运行npm start
我正在尝试通过使用访问RAZORPAY.KEY
process.env.ORGANIZATION["b0fd9120-deb7-55t6-b269-c1622a43e9af"].RAZORPAY.KEY
但无法获取错误。
TypeError:无法读取未定义的属性“ RAZORPAY”
我通过pm2 start ecosystem.config.js --env staging --update-env
启动我的应用
ORGANIZATION
之外的所有其他env变量都可以访问。