I have built my react files with a .env file containing various base URLs and API keys, using env-cmd -f .env.production craco build when .env.production being my env file.
After building I want to serve these files using PM2 command pm2 server <build location> <port>
I am successfully able to host my my static files at my desired port, but my static files are not able to read any values from .env.production file. Can anyone guide me how to use environment variables pm2 from my env file?
Also I tried to create an ecosystem.config.js for pm2 to serve my static files and store the env values inside it too. Here is the file:
module.exports = {
script: "serve",
env: {
PM2_SERVE_PATH: '.',
PM2_SERVE_PORT: 3011,
REACT_APP_MAPBOX_API_KEY : 'mykey',
REACT_APP_COG_URL : 'http://localhost:8000',
REACT_APP_LIVE_URL : 'https://something.com',
REACT_APP_RTMP_URL : 'rtmp://something.com/stream',
REACT_APP_BASE_URL : 'http://localhost:5011',
REACT_APP_SERVER_URL : 'https://something.com'
}
}
But the above config file only works the script and port part. Nothing else works
Thanking you in advance