Get value of another property in the same nodejs object

I have the following code in my hapijs project (nodejs)

var t = require('joi');
var bdd = require('./../bdd');

module.exports = [
{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
          //some code
    },
    config:{
        description: this.path + " route."
    }
}
];

      

But when my route loads, I see:

: description = undefined ....

How to set this value?

+3


source to share


2 answers


Your example this

does not refer to the object you are trying to export. What you can do is use a function at this point called getConfig

to return an object with this information:

module.exports = [{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
        //some code
    },
    getConfig: function () {
        return {
            description: this.path + " route."
        }
    }
}]


obj[0].getConfig().description; // "/getAllParties route."

      



DEMO

0


source


You skipped it];



var t = require('joi');
var bdd = require('./../bdd');

module.exports = [
{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
          //some code
    },
    config:{
        description: this.path + " route."
    }
}

      

-2


source







All Articles