0

I have the following function :

module.exports = {
    PDF_Function: function (url) {

        (async () => {
            console.log("Our URL => "+url);
            const url = 'http://localhost:81/site/products/travel/mpdf';
            const buffer = await Webpage.generatePDF(url);
           return '1';
        })();

    }
};

How can I access the URL value from PDF_Function: function (url) inside the async function, when I tried to console it I get the following error =>

(node:66420) UnhandledPromiseRejectionWarning: ReferenceError: Cannot access 'url' before initialization
H Dindi
  • 1,484
  • 6
  • 39
  • 68

1 Answers1

0

You should avoid same variable names:

module.exports = {
        PDF_Function: function (urlAsArgument) {

            (async () => {
                console.log("Our URL => "+ urlAsArgument);
                const url = 'http://localhost:81/site/products/travel/mpdf';
                const buffer = await Webpage.generatePDF(url);
               return '1';
            })();

        }
    };

Your argument name in PDF_Function and a const name inside your async function were same.

I hope it will help.

Arpit Kumar
  • 2,179
  • 5
  • 28
  • 53