env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

It seems env-cmd not working with pm2

Open ujjavaljani opened this issue 4 years ago • 2 comments

Hello, I am using env-cmd in my typescript application. for production I am creating node js build using tsc and after build when I tried to pass custom env file then it throws error like .env file could not found.

image

I am trying to run command npm run pm2:start:qa.

Thanks in advance.

ujjavaljani avatar Jul 12 '21 17:07 ujjavaljani

Perhaps this could help. Create an pm2.config.js file, define your configs in there and access the ENV variables as show below.

module.exports = {
    apps: [
        {
            name: "app-namne",
            script: "./build/index.js",
            watch: true,
            ignore_watch: [
                ".git",
                ".md",
            ],
            time: true,
            env: {
                PORT: process.env.PORT,
            },
        },
    ],
};

qa start script should look something like this:

npm run build && env-cmd -f ./environments/.env pm2 start pm2.config.js",

erassynathingo avatar Mar 15 '22 18:03 erassynathingo