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
2
  • @Adam Agreed, finding the right dupe. Let me fix that. Commented Aug 1, 2019 at 13:43
  • @Adam Updated. Thanks. Commented Aug 1, 2019 at 13:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

What's the change you have done?
Ah great find... 😇
The argument name and the const name (url) both were same.
Yep, noticed it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.