Convert a multidimensional object to environment variables

38 views
Skip to first unread message

Kevin Ingwersen (Ingwie Phoenix)

unread,
Jul 4, 2015, 11:01:43 PM7/4/15
to nod...@googlegroups.com
Imagine you are going to run a sub-process that does not understand JSON for some reason and your configuration has ultiple levels. So what do we do? Imagine this:

{
foo: 1,
bar: 2
banker: {
name: someName
}
}

Now I would want this to become:

foo=1
bar=2
banker_name=someName

Is there a module for that?

Ryan Graham

unread,
Jul 5, 2015, 12:33:27 AM7/5/15
to nod...@googlegroups.com
That reminds me of what https://www.npmjs.com/package/nconf does when converting back and forth between environment variables and nested/namespaced config objects.

~Ryan

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/76CD1215-273E-4BF3-A2B6-0C722635AD1D%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Pieter Sheth-Voss

unread,
Jul 6, 2015, 2:03:20 PM7/6/15
to nod...@googlegroups.com
Another package that does that is dotenv (https://github.com/motdotla/dotenv).  The essence of it is in the snippet below which directly assigns the environment variables:


Object.keys(parsedObj).forEach(function (key) {
  process
.env[key] = process.env[key] || parsedObj[key] })
});


Alexander Praetorius

unread,
Jul 8, 2015, 1:39:21 PM7/8/15
to nod...@googlegroups.com
I'm not sure if thats really related to the topic, but i wrote https://github.com/serapath/envlocalify and its useful for someone in their project, i'd welcome feedback :-)


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages