I have a config file for my Node.js application which looks like this:
// Development specific configuration
// ==================================
module.exports = {
....
ip: "localhost",
//Rabbit MQ
rabbitmq: {
username: 'foo',
password: 'bar',
ip: 'amqp://'+this.username+':'+this.password+'@rabbitmq',
queues: {
name: 'foo'
}
},
....
};
Here is what the module looks like where I use this config file:
var config = require ('../../config/environment');
this.con = amqp.connect (config.rabbitmq.ip);
I am getting undefined for the username and password:
amqp://undefined:undefined@rabbitmq
I have tried multiple ways such as:
Creating getter functions inside the object like this:
rabbitmq: { username: 'foo', password: 'bar', getUsername: function (){ return this.username; }, getpassword: function (){ return this.password; }, ip: 'amqp://'+this.getUsername()+':'+this.getpassword()+'@rabbitmq',
Created a self value and assign 'this' and reference it:
self: this, ... ip: 'amqp://'+self.rabbitmq.username+':'+self.rabbitmq.password+'@rabbitmq',
..
I cannot get the scope to properly work. Am I missing something basic? How can I make this happen? Please help.