By Hooman
I am trying to pass some arguments to my Express application which is run by pm2. There wasn’t any hint in their documentation to do so, but apparently it’s possible to pass some EV to your node application like
SOME_STUFF=xxx pm2 start app.js
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This makes me wonder, in most other cases I’m storing things like third party api keys in my .env file. When I run my app on ubuntu I do env $(cat .env) pm2 start .... Is the process.json file expected to be checked into the repo? If so, I wouldn’t want to embed my api keys and what not. Would be nice if pm2 could source the .env file on start up (or specify a file that has the environment vars) so they don’t have to be embeded into a checked in file…
Correct - You would use something such as:
USER_ID=123456 USER_KEY=foo node app.js
…to pass environment variables and then access them using
process.env.USER_ID
and
process.env.USER_KEY
If you need to pass multiple variables, you could also use a process.json/yml file, see here:
Then start like: pm2 start process.[json|yml]
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.