Thursday, 11 May 2017

Accessing config vars with PHP and Node.js in Heroku

I'd like to access some config vars in a PHP file on a Heroku web app.
The app runs (and starts) with Node.js and utilizes both Node.js and PHP buildpacks from Heroku.

What I want to happen

I would like to be able to start the app with Node.js and access the environment variables in my PHP file.

What actually happens

When I start the app with Node.js, the config vars are accessible through process.env('SOME_KEY') (in the js file), and when I don't use Node.js and start in PHP the variables are accessible through getenv('SOME_KEY'), but when I start in Node.js getenv('SOME_KEY') (in the PHP file) returns undefined (likewise with $_ENV['SOME_KEY']).

I'd appreciate it if someone could explain why it's not accessible in PHP, if there is a way to make it accessible through PHP, or a way to send the variables from Node.js to the PHP file. Thank you!



via Jeremy E.

No comments:

Post a Comment