PM2生态系统.config.js嵌套环境变量

时间:2019-09-25 12:15:59

标签: node.js environment-variables pm2

我的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变量都可以访问。

0 个答案:

没有答案