I have a server.js file that includes the module puppeteer.
const puppeteer = require('puppeteer');
I want to run a function inside routes.js that uses that module.
async function getPic(arg) {
const browser = await puppeteer.launch(/*{headless: false}*/);
const page = await browser.newPage();
await page.goto(arg);
await page.setViewport({width: 1000, height: 500})
await page.screenshot({path: 'pic.png'});
await broswer.close();
}
When i attempt to run this then it doesn't work because "puppeteer is not defined".
So what is the most optimal way to solve this? Obvisouly i cannot reinclude the puppeteer module in routes.js So do i include the server.js file in routes.js? Or this might cause modules and variables and functions to be instantiated twice? (one time when server.js ran - as it is the starting point, and one time when routes.js ran and reruns server.js)