title: How can I pass an argument into my Javascript code from command line?
body: <p>My JS file &quot;login.js&quot; can be run from the command line with &quot;node login.js&quot;. If I want to change the URL used I have to go into the file and edit the URL.</p>
  <p>I'd like to be able to pass the URL as an argument via the command line, eg &quot;node login.js https://example.com&quot; and for the code to use that URL. I assume this is fairly straightforward but I can't seem to work it out from reading about it online.</p>
  <pre><code>const puppeteer = require('puppeteer');
  const C = require('./constants');
  const USERNAME_SELECTOR = '#email';
  const PASSWORD_SELECTOR = '#password';
  const CTA_SELECTOR = '#next';
  const CTA_SELECTOR2 = '#submit-btn';
  
  
  async function startBrowser() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    return {browser, page};
  }
  
  
  async function closeBrowser(browser) {
    return browser.close();
  }
  
  async function playTest(url) {
    const {browser, page} = await startBrowser();
    page.setViewport({width: 1366, height: 768});
    await page.goto(url);
    await page.waitForSelector(USERNAME_SELECTOR);
    await page.click(USERNAME_SELECTOR);
    await page.keyboard.type(C.username);
    await page.click(CTA_SELECTOR);
    console.log('before waiting');
  await delay(10000);
  console.log('after waiting');
    await page.click(PASSWORD_SELECTOR);
    await page.keyboard.type(C.password);
    await page.click(CTA_SELECTOR2);
    await page.waitForNavigation();
    await page.screenshot({path: 'screenshot.png'});
  }
  
  (async () =&gt; {
    await playTest(&quot;https://example.com&quot;);
    process.exit(1);
  })();
  
  function delay(time) {
    return new Promise(function(resolve) { 
        setTimeout(resolve, time)
    });
  }
  </code></pre>