env-cmd
env-cmd copied to clipboard
It seems env-cmd not working with pm2
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.

I am trying to run command npm run pm2:start:qa.
Thanks in advance.
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",