Received: by 10.14.11.83 with SMTP id 59mr678172eew.13.1300989944407; Thu, 24 Mar 2011 11:05:44 -0700 (PDT) X-BeenThere: nodejs@googlegroups.com Received: by 10.14.25.139 with SMTP id z11ls94908eez.0.p; Thu, 24 Mar 2011 11:05:37 -0700 (PDT) Received: by 10.14.14.7 with SMTP id c7mr613738eec.17.1300989937443; Thu, 24 Mar 2011 11:05:37 -0700 (PDT) Received: by 10.14.14.7 with SMTP id c7mr613736eec.17.1300989937427; Thu, 24 Mar 2011 11:05:37 -0700 (PDT) Return-Path: Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by gmr-mx.google.com with ESMTPS id p52si46172eeh.7.2011.03.24.11.05.36 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Mar 2011 11:05:36 -0700 (PDT) Received-SPF: pass (google.com: domain of isaacschlue...@gmail.com designates 209.85.215.180 as permitted sender) client-ip=209.85.215.180; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of isaacschlue...@gmail.com designates 209.85.215.180 as permitted sender) smtp.mail=isaacschlue...@gmail.com; dkim=pass (test mode) header...@gmail.com Received: by eyg24 with SMTP id 24so142074eyg.25 for ; Thu, 24 Mar 2011 11:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=jz3sSyZvn3axxf41i6bvcV+2qP1oZRv74ON16vbcfCg=; b=VKXztB1Aja2mVTW89/ljlilwopolH6fH7rNtRupJju5sPYA8Gp6EgfHIbl+YnkuSdI 9ZuWqddWeGdX8LT8Bz4dZcYfObY2Csv0UzaED5Qi7mUmKgz3DcIvE+7At3CTwXb2Ztch JUea76VxZ3ec4vaJQC3lZJRf5MhDvYTO10OUQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=JkRkZmpOn6YO+6reH6G1Tf4IPGH2DKHMtVraf6sozaLccw+3J9JMT4pELRxT074RUI pAiVbj7ydUKlWOh41jzDJ9dy65/O0N+0tsFOmejJK/3StOzTGSBhTH4SEalOqLvkxC5+ 7VxY6C0T2jBQtnGwhy18J33K8nSBZp3yYey6Q= MIME-Version: 1.0 Received: by 10.216.67.194 with SMTP id j44mr7752741wed.41.1300989935884; Thu, 24 Mar 2011 11:05:35 -0700 (PDT) Sender: isaacschlue...@gmail.com Received: by 10.216.55.133 with HTTP; Thu, 24 Mar 2011 11:05:35 -0700 (PDT) In-Reply-To: References: <4755C3ED057645B5A2A270C7BFC54...@nbtsc.org> <96c1b088-5fca-4d35-8ad2-7d2a9ae19...@a11g2000pri.googlegroups.com> Date: Thu, 24 Mar 2011 11:05:35 -0700 Message-ID: Subject: Re: [nodejs] Re: Setup environment variables? From: Isaac Schlueter To: nodejs@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Matt answered your question above. Let's say you have this in your server.js file: if (process.env.SERVER =3D=3D=3D "PRODUCTION") { .. produce stuff .. } There are many ways to set environment variables. You can set them on the command line for just one command: $ SERVER=3DPRODUCTION node server.js You can export them into your shell environment: $ export SERVER=3DPRODUCTION $ node server.js You can export them from a shell script: # foo.sh export SERVER=3DPRODUCTION $ 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=3DPRODUCTION >> server-profile $ echo FOO=3Dbar >> 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 =3D environ; environ =3D { "SERVER=3DPRODUCTION" }; ret =3D execvp("node", { "server.js" }); environ =3D saved_env; return ret; } If you're loading your program from your bash login shell, you can put this in your ~/.bashrc: export SERVER=3DPRODUCTION If you're running it with SMF, you can put this in your manifest xml: 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 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? =C2=A0 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 wrote: >> On Mar 24, 12:28=C2=A0pm, Guy Halford-Thompson 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'] =3D 8; // Set >> console.log(process.env['JOBS']); // Get >> >> -- >> You received this message because you are subscribed to the Google Group= s "nodejs" group. >> To post to this group, send email to nodejs@googlegroups.com. >> To unsubscribe from this group, send email to nodejs+unsubscribe@googleg= roups.com. >> For more options, visit this group at http://groups.google.com/group/nod= ejs?hl=3Den. >> >> > > > > -- > Guy Halford-Thompson - http://www.cach.me/blog > > -- > 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@googlegr= oups.com. > For more options, visit this group at http://groups.google.com/group/node= js?hl=3Den. > >