Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Setup environment variables?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Guy Halford-Thompson  
View profile  
 More options Mar 24 2011, 12:15 pm
From: Guy Halford-Thompson <g...@cach.me>
Date: Thu, 24 Mar 2011 16:15:52 +0000
Local: Thurs, Mar 24 2011 12:15 pm
Subject: Setup environment variables?
What is the best way to setup environment variables (e.g. DEVELOPMENT,
PRODUCTION, TESTING) in node?

I use different ports and database info for test/production servers
and was wondering what the best way to make this a bit more automated
is.

Thanks

--
Guy Halford-Thompson - http://www.cach.me/blog


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aria Stewart  
View profile  
 More options Mar 24 2011, 12:18 pm
From: Aria Stewart <aredri...@nbtsc.org>
Date: Thu, 24 Mar 2011 10:18:05 -0600
Local: Thurs, Mar 24 2011 12:18 pm
Subject: Re: [nodejs] Setup environment variables?
On Thursday, March 24, 2011 at 10:15 AM, Guy Halford-Thompson wrote:

What is the best way to setup environment variables (e.g. DEVELOPMENT,

> PRODUCTION, TESTING) in node?

> I use different ports and database info for test/production servers
> and was wondering what the best way to make this a bit more automated
> is.

Look at process.env?
----
Aria Stewart

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guy Halford-Thompson  
View profile  
 More options Mar 24 2011, 12:28 pm
From: Guy Halford-Thompson <g...@cach.me>
Date: Thu, 24 Mar 2011 16:28:29 +0000
Local: Thurs, Mar 24 2011 12:28 pm
Subject: Re: [nodejs] Setup environment variables?
I have, but there is only a couple of lines of documentation... could
someone point me to an example?

Ty

On 24 March 2011 16:18, Aria Stewart <aredri...@nbtsc.org> wrote:

--
Guy Halford-Thompson - http://www.cach.me/blog

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt  
View profile  
 More options Mar 24 2011, 12:58 pm
From: Matt <hel...@gmail.com>
Date: Thu, 24 Mar 2011 12:58:16 -0400
Local: Thurs, Mar 24 2011 12:58 pm
Subject: Re: [nodejs] Setup environment variables?

if (process.env.DEVELOPMENT) {
// setup devel stuff

}

else if (process.env.TESTING) {
// setup testing stuff
}

else {
// assume production

}

then start in bash as: DEVELOPMENT=1 node code.js


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mscdex  
View profile  
 More options Mar 24 2011, 12:59 pm
From: mscdex <msc...@gmail.com>
Date: Thu, 24 Mar 2011 09:59:13 -0700 (PDT)
Local: Thurs, Mar 24 2011 12:59 pm
Subject: Re: Setup environment variables?
On Mar 24, 12:28 pm, Guy Halford-Thompson <g...@cach.me> wrote:

> I have, but there is only a couple of lines of documentation... could
> someone point me to an example?

It's just a plain js object:

process.env['JOBS'] = 8; // Set
console.log(process.env['JOBS']); // Get


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guy Halford-Thompson  
View profile  
 More options Mar 24 2011, 1:33 pm
From: Guy Halford-Thompson <g...@cach.me>
Date: Thu, 24 Mar 2011 17:33:00 +0000
Subject: Re: [nodejs] Re: Setup environment variables?
Sorry, I should have been a bit more specific in my question... I was
wondering how to set the variables on the server, not access them in
node

I understand how you can access
....
process.env['JOBS']
...

but how do I set the variable 'JOBS' on my server?   This cannot be
done in my node files as they will be the same on all servers.

Thanks for the help

G

On 24 March 2011 16:59, mscdex <msc...@gmail.com> wrote:

--
Guy Halford-Thompson - http://www.cach.me/blog

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Corey Jewett  
View profile  
 More options Mar 24 2011, 1:59 pm
From: Corey Jewett <corey.jew...@gmail.com>
Date: Thu, 24 Mar 2011 10:59:08 -0700
Local: Thurs, Mar 24 2011 1:59 pm
Subject: Re: [nodejs] Re: Setup environment variables?
On Mar 24, 2011, at 10:33 , Guy Halford-Thompson wrote:

> Sorry, I should have been a bit more specific in my question... I was
> wondering how to set the variables on the server, not access them in
> node

> I understand how you can access
> ....
> process.env['JOBS']
> ...

> but how do I set the variable 'JOBS' on my server?   This cannot be
> done in my node files as they will be the same on all servers.

Depends on your shell's syntax for environment variables (google  
that), but typically:

$> JOBS=123
$> export JOBS
$> node
 > process.env["JOBS"]
'123'

Corey


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Isaac Schlueter  
View profile  
 More options Mar 24 2011, 2:05 pm
From: Isaac Schlueter <i...@izs.me>
Date: Thu, 24 Mar 2011 11:05:35 -0700
Local: Thurs, Mar 24 2011 2:05 pm
Subject: Re: [nodejs] Re: Setup environment variables?
Matt answered your question above.

Let's say you have this in your server.js file:

if (process.env.SERVER === "PRODUCTION") { .. produce stuff .. }

There are many ways to set environment variables.

You can set them on the command line for just one command:

$ SERVER=PRODUCTION node server.js

You can export them into your shell environment:

$ export SERVER=PRODUCTION
$ node server.js

You can export them from a shell script:

# foo.sh
export SERVER=PRODUCTION

$ source foo.sh # not ./foo.sh! that would run in a subshell
$ node server.js

You can pass a key-value list to the "env" command:

$ echo SERVER=PRODUCTION >> server-profile
$ echo FOO=bar >> server-profile
$ env $(cat server-profile) node server.js

If you're starting your program with node's child_process.spawn, you
can pass them on the options object:

child_process.spawn("node", ["server.js"], { env: { SERVER: "PRODUCTION" }})

If you're starting your program with execp in C, you can use the
"environ" extern.

extern char **environ;
int main (int argc, char** argv) {
  char **saved_env;
  int ret;
  saved_env = environ;
  environ = { "SERVER=PRODUCTION" };
  ret = execvp("node", { "server.js" });
  environ = saved_env;
  return ret;

}

If you're loading your program from your bash login shell, you can put
this in your ~/.bashrc:

export SERVER=PRODUCTION

If you're running it with SMF, you can put this in your manifest xml:
<method_environment>
  <envvar name="SERVER" value="PRODUCTION"/>
</method_environment>

There are probably other ways to set environment vars.  "man sh" and
"man bash" have sections on this.

Environs are a pretty core Unix feature.  Think of it like another set
of arguments to your program.

--i


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt  
View profile  
 More options Mar 24 2011, 2:45 pm
From: Matt <hel...@gmail.com>
Date: Thu, 24 Mar 2011 14:45:30 -0400
Local: Thurs, Mar 24 2011 2:45 pm
Subject: Re: [nodejs] Re: Setup environment variables?

It's pretty basic unix knowledge.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guy Halford-Thompson  
View profile  
 More options Mar 24 2011, 2:18 pm
From: Guy Halford-Thompson <g...@cach.me>
Date: Thu, 24 Mar 2011 18:18:32 +0000
Local: Thurs, Mar 24 2011 2:18 pm
Subject: Re: [nodejs] Re: Setup environment variables?
Hi Isaac,

Thanks for your detailed response, that makes it very clear. Would it
be worth adding this to the documentation at some point? Or is it just
be being v inexperienced...

Thanks also to everyone else for you help.

Guy

On 24 March 2011 18:05, Isaac Schlueter <i...@izs.me> wrote:

--
Guy Halford-Thompson - http://www.cach.me/blog

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Tolley  
View profile  
 More options Nov 12 2012, 9:07 pm
From: Adam Tolley <adam.tol...@gmail.com>
Date: Mon, 12 Nov 2012 18:07:26 -0800 (PST)
Local: Mon, Nov 12 2012 9:07 pm
Subject: Re: [nodejs] Re: Setup environment variables?

Setting environment vars is pretty basic unix knowledge - what was lost on
me is that process.env contained those variables.  I assumed nodejs had its
own environment vars set up by passing in arguments on launch, or a file,
not just bootstrapping the current shell environment - thats pretty slick.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »