WebFaction
Community site: login faq

Is there a way to create persistent environment variables that apply on a per-app basis?

For example, say I have two node apps running on my webfaction account. I want one to have a NODE_ENV of production and the other to have a NODE_ENV of development, so that when I access the process.env.NODE_ENV in each node app, I get the right value.

I found this question and answer but the solution there would have the variables apply across all apps, I think.

asked 13 Sep '15, 10:39

negatron
134
accept rate: 0%


You can export your variables in your node's start script at the ~/webapps/<app_name>/bin/start file.

You can write the following line for example ...

export NODE_ENV='production'

... and you should then be able to access it with your code using process.env.NODE_ENV.

You can have multiple lines like that, passing any variable you want, but please note that they should be declared before the line starting with nohup.

permanent link

answered 13 Sep '15, 11:33

iliasr ♦♦
2.1k14
accept rate: 35%

edited 13 Sep '15, 11:34

That's brilliant, thank you! I assume that doing this will not effect other apps running on the same account right?

(13 Sep '15, 11:56) negatron

No, it shouldn't.

The export commands in the start script will make the environment variables available only for the processes started by that script.

Other processes under the same username will not be able to have direct access to the them.

(13 Sep '15, 12:03) iliasr ♦♦

This is exactly what I need then, thanks a lot!

(13 Sep '15, 12:07) negatron
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×67
×11

question asked: 13 Sep '15, 10:39

question was seen: 1,407 times

last updated: 13 Sep '15, 12:07

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM