5

I've tried using:

db:
  uri: process.env.MONGOLAB_URI

but that doesn't seem to be working. (EDIT: in fact, that just returns the string of "process.env.MONGOLAB_URI") I've also tried:

<%= ENV['MONGOLAB_URI'] %>

but I saw that in article for an article about yaml in a ruby app (can't find the link now).

What's the correct syntax?

Miles
  • 1,615
  • 4
  • 17
  • 42

2 Answers2

0

db: uri: #{process.env.MONGOLAB_URI}

credits: https://github.com/vngrs/konfig

kaushik94
  • 687
  • 6
  • 17
-1

I believe the config.yaml example is for a specific Ruby driver. For Node.js you want to feed the URI (found at process.env.MONGOLAB_URI) into the Node driver of your choice using whatever configuration method you find most convenient.

If you wanted to use the Node MongoDB Native driver for example you might do something like this:

var mongodb = require('mongodb');
mongodb.Db.connect(process.env.MONGOLAB_URI, function (err, db) {
    // Do something cool with the db
});
jared
  • 5,369
  • 2
  • 21
  • 24
  • Right, and that works when placing `process.env.MONGOLAB_URI` in the node.js code, but what syntax should be used to put it in the `config.yaml`? – Miles Oct 03 '12 at 21:40
  • If you're referring to the YAML file configuration technique documented in the [MongoLab add-on help](https://devcenter.heroku.com/articles/mongolab), then as I mentioned that's for a particular Ruby driver and doesn't apply to Node.js. Is the problem that you're looking to externalize the configuration from the code and perhaps fork on the environment being used? – jared Oct 03 '12 at 22:28
  • I guess I'm not being clear. I understand that one of the syntaxes I used in the question is for ruby and not for node.js, that's why I said that in the question. I also understand that I can access the mongolab_uri environmental variable in javascript code by using `process.env.MONGOLAB_URI` in the node.js code. The problem is that when using a yaml file for app config, you can't use `process.env.MONGOLAB_UI` by itself, because yaml will just return that string and not evaluate the string as javascript code. What's the syntax to tell yaml that it should evaluate the string as javscript? – Miles Oct 04 '12 at 03:20
  • I believe that depends on the YAML parser you're using. Are you using [js-yaml](https://github.com/nodeca/js-yaml)? I don't see an obvious solution from a quick review of the README.md or a visit to their [online demo](http://nodeca.github.com/js-yaml/). Taking a step back, though, YAML isn't the usual way to handle configuration in Node. You may want to try one of the [techniques more commonly used with Node](http://stackoverflow.com/questions/5869216/how-to-store-node-js-deployment-settings-configuration-files). I use [nconf](https://github.com/flatiron/nconf) myself. – jared Oct 04 '12 at 17:13
  • nconf looks really sweet. The way it automatically processes and incorporates environmental variables might solve my issue. I'll check it out. Thanks! And sorry for the confusion – Miles Oct 06 '12 at 04:07