In this video, you will learn how to pass environment variables to your node.js app using the pm2 config file. This is useful for setting options inside your app such as production or development.
If we start our app up, our app is up and running. Watching is enabled. Now, if we edit app1 server.js, and if we do something like add process.env.NODE_ENV, and we concatenate that inside of our string, we save that, PM2 list is going to show us that PM2 reloaded the app after detecting change in the files. If we refresh our page, we get, "Hello from app1 production," which is the value of the environment variable we passed in.
You must be a Pro Member to view code
Access all courses and lessons, track your progress, gain confidence and expertise.