> 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 received this message because you are subscribed to the Google Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com. > To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
On Thu, Mar 24, 2011 at 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?
> Ty
> On 24 March 2011 16:18, Aria Stewart <aredri...@nbtsc.org> wrote: > > 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 received this message because you are subscribed to the Google Groups > "nodejs" group. > > To post to this group, send email to nodejs@googlegroups.com. > > To unsubscribe from this group, send email to > nodejs+unsubscribe@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en.
> -- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com. > To unsubscribe from this group, send email to > nodejs+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en.
> 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 received this message because you are subscribed to the Google Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com. > To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
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.
On Thu, Mar 24, 2011 at 10:33, Guy Halford-Thompson <g...@cach.me> 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.
> Thanks for the help
> G
> On 24 March 2011 16:59, mscdex <msc...@gmail.com> wrote: >> 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 received this message because you are subscribed to the Google Groups "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com. >> To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com. > To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
On Thu, Mar 24, 2011 at 2:18 PM, Guy Halford-Thompson <g...@cach.me> wrote: > 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 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:
> 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
> On Thu, Mar 24, 2011 at 10:33, Guy Halford-Thompson <g...@cach.me> 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.
>> Thanks for the help
>> G
>> On 24 March 2011 16:59, mscdex <msc...@gmail.com> wrote: >>> 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 received this message because you are subscribed to the Google Groups "nodejs" group. >>> To post to this group, send email to nodejs@googlegroups.com. >>> To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. >>> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>> -- >> You received this message because you are subscribed to the Google Groups "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com. >> To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com. > To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
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.
On Thursday, March 24, 2011 2:45:30 PM UTC-4, Matt Sergeant wrote:
> It's pretty basic unix knowledge.
> On Thu, Mar 24, 2011 at 2:18 PM, Guy Halford-Thompson <g...@cach.me<javascript:> > > wrote:
>> 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...