I was referring to how angular js connects to mongo db. So while setting the url and port for the 'db' object, I found code like below:
var path = require('path'),
rootPath = path.normalize(__dirname + '/../..');
module.exports = {
root: rootPath,
port: process.env.PORT || 3000,
db: process.env.MONGOHQ_URL
}
Will someone please let me know what is this path here for? And also, what is the default value of MONGOHQ_URL here?
From the link http://docs.mongohq.com/languages/nodejs.html , I came to know mongo url can be set to :
var MONGOHQ_URL="mongodb://user:pass@server.mongohq.com:port_name/db_name"
Am I right?
Thanks, Sabari
The MONGOHQ_URL
in your code snippet comes from the shell environment. For example, in bash
you would add that to your ~/.bash_profile
:
export MONGOHQ_URL="mongodb://user:pass@server.mongohq.com:port_name/db_name"
... or include on your command line when starting the node app:
MONGOHQ_URL="mongodb://user:pass@server.mongohq.com:port_name/db_name" node app.js
Another common approach with Node.js is to use something like dotenv
, which will load environment variables from a .env
directory in your project.
And also, what is the default value of MONGOHQ_URL here?
There is no default; you need to define this if you want to connect to a MongoHQ instance.