Pass variable to main function Nodejs

Sean Berrie

Basically I'm trying to pass the "Browser" variable on to my main function, to pass on to "CheckStock". I've tried many thing but just can't seem to find a way how to do this. If anyone knows how to, please let me know. Thanks in advance! :)

// STARTUP BROWSER & GO TO URL
async function openBrowser(monitorURL) {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto(monitorURL)
  return browser, page;
}

/* 
...
...
...
other code
...
...
...
*/

// MAIN FUNCTION
async function monitor(monitorURL){
  const page  = await openBrowser(monitorURL);
  await checkStock(page, browser)
}
jfriend00

You need to change how you return the two values to this (so they are both available in a returned object):

async function openBrowser(monitorURL) {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto(monitorURL)
  return {browser, page};
}

And, then how you get them both out of that object:

// MAIN FUNCTION
async function monitor(monitorURL){
  const {page, browser} = await openBrowser(monitorURL);
  await checkStock(page, browser);
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Trying to pass variable to Wordpress function

分類Dev

Pass variable to void function in flutter

分類Dev

Javascript pass variable to function name

分類Dev

python pass variable to function parameter

分類Dev

Pass NodeJS callback from exported function to view

分類Dev

How to pass variable to a function declared in another function

分類Dev

JQuery pass a variable from function to function

分類Dev

How to pass a variable from main to signal and slot macros?

分類Dev

how can i pass variable in parameter as a function?

分類Dev

Pass local variable to a signal handler function

分類Dev

How to pass a python event variable into another function?

分類Dev

pass a list of variable names as an argument to an R function

分類Dev

Pass in Django Template Variable to JS function

分類Dev

How to pass assign variable value in FreeMarker function

分類Dev

How to pass String Variable in Javascript Function?

分類Dev

Python : How to pass a value to a variable that is a function...?

分類Dev

Pass a variable to a PHP function, even if undefined

分類Dev

How to pass js variable to Rails function

分類Dev

A function is outside main,it requires use of a variable how do use it?

分類Dev

main.o:main.c:function main:エラー:「variable_name」への未定義の参照

分類Dev

How to pass a bool variable by reference in a non-bool function?

分類Dev

How to pass JavaScript variable to Symfony route using Twig path function

分類Dev

Is there a way to pass a variable into a class like you do a function in SwiftUI?

分類Dev

How to pass a member function which has variable arguments as template argument?

分類Dev

Pass a variable from a javascript function to another php file

分類Dev

How to pass a function variable to a jQuery event on a Backbone model?

分類Dev

How to pass a function variable to a jQuery event on a Backbone model?

分類Dev

Codeigniter categories and sub categories function and pass to smarty variable

分類Dev

Pass Python variable from one function to another to compare it with the variable of a SQL database

Related 関連記事

  1. 1

    Trying to pass variable to Wordpress function

  2. 2

    Pass variable to void function in flutter

  3. 3

    Javascript pass variable to function name

  4. 4

    python pass variable to function parameter

  5. 5

    Pass NodeJS callback from exported function to view

  6. 6

    How to pass variable to a function declared in another function

  7. 7

    JQuery pass a variable from function to function

  8. 8

    How to pass a variable from main to signal and slot macros?

  9. 9

    how can i pass variable in parameter as a function?

  10. 10

    Pass local variable to a signal handler function

  11. 11

    How to pass a python event variable into another function?

  12. 12

    pass a list of variable names as an argument to an R function

  13. 13

    Pass in Django Template Variable to JS function

  14. 14

    How to pass assign variable value in FreeMarker function

  15. 15

    How to pass String Variable in Javascript Function?

  16. 16

    Python : How to pass a value to a variable that is a function...?

  17. 17

    Pass a variable to a PHP function, even if undefined

  18. 18

    How to pass js variable to Rails function

  19. 19

    A function is outside main,it requires use of a variable how do use it?

  20. 20

    main.o:main.c:function main:エラー:「variable_name」への未定義の参照

  21. 21

    How to pass a bool variable by reference in a non-bool function?

  22. 22

    How to pass JavaScript variable to Symfony route using Twig path function

  23. 23

    Is there a way to pass a variable into a class like you do a function in SwiftUI?

  24. 24

    How to pass a member function which has variable arguments as template argument?

  25. 25

    Pass a variable from a javascript function to another php file

  26. 26

    How to pass a function variable to a jQuery event on a Backbone model?

  27. 27

    How to pass a function variable to a jQuery event on a Backbone model?

  28. 28

    Codeigniter categories and sub categories function and pass to smarty variable

  29. 29

    Pass Python variable from one function to another to compare it with the variable of a SQL database

ホットタグ

アーカイブ