Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  173] [ 3]  / answers: 1 / hits: 142687  / 9 Years ago, wed, july 22, 2015, 12:00:00

I have an array that I pull data from.



festivals = ['bonnaroo', 'lollapalooza', 'coachella']


Since I'm using heroku, it may be better to replace it with an environment variable, but I'm not sure how to do that.



Is using a JSON string as an environment variable the way to go?


More From » node.js

 Answers
59

In this scenario, it doesn't sound like an env var is the way to go.



Usually, you'll want to use environment variables to give your application information about its environment or to customize its behavior: which database to connect to, which auth tokens to use, how many workers to fork, whether or not to cache rendered views, etc.



Your example looks more like a model, so something like a database is probably a better fit.



That said, there's no context around what your app does or how it uses festivals, so if it does turn out that you should use an env var, then you have several options. The simplest is probably to just use a space or comma-delimited string:



heroku config:set FESTIVALS=bonnaroo lollapalooza coachella


then:



var festivals = process.env.FESTIVALS.split(' ');


disclosure: I'm the Node.js Platform Owner at Heroku


[#65730] Sunday, July 19, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rhiannab

Total Points: 370
Total Questions: 98
Total Answers: 100

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;